/* Author: 

*/

var map;  
var panorama; 
var latlng;


$(document).ready(function(){
	$('div.article').each(function(index){
	    if ($('h2', this).length > 0 && $('div', this).length > 0) {
			if (!$(this).hasClass('static')) {
				headline = $('h2', this);
				headline.css('cursor', 'pointer');
				if (index == 0) { 
					headline.append('<span>[weniger]</span>');
				} else {
					headline.append('<span>[mehr]</span>');
				    $('div:first', $(this)).hide();				
				}
				headline.bind('click', function(){
					mySlideToggle($(this).next());
					var span = $(this).children('span:first');
					var text = span.text();
					text = (text == '[mehr]' ? '[weniger]' : '[mehr]');
					span.text(text);
				});
			}
		}
	})
	
	if ($('#gallery').length) {
		Galleria.loadTheme('/js/libs/galleria/themes/classic/galleria.classic.min.js');
		$("#gallery").galleria({
		        width: 650,
		        height: 600,
		});
	}
	
	if ($('#map').length > 0) {
		
		initializeMap();
		// $('#streetview-button').click(toggleStreetView);
	}
});




function mySlideToggle(el, bShow){
  var $el = $(el), height = $el.data("originalHeight"), visible = $el.is(":visible");
  
  // if the bShow isn't present, get the current visibility and reverse it
  if( arguments.length == 1 ) bShow = !visible;
  
  // if the current visiblilty is the same as the requested state, cancel
  if( bShow == visible ) return false;
  
  // get the original height
  if( !height ){
    // get original height
    height = $el.show().height();
    // update the height
    $el.data("originalHeight", height);
    // if the element was hidden, hide it again
    if( !visible ) $el.hide().css({height: 0});
  }

  // expand the knowledge (instead of slideDown/Up, use custom animation which applies fix)
  if( bShow ){
    $el.show().animate({height: height}, {duration: 500});
  } else {
    $el.animate({height: 0}, {duration: 500, complete:function (){
        $el.hide();
      }
    });
  }
}

function initializeMap() {   
	var latlng = new google.maps.LatLng(53.574206,9.845484);
	var latlng_jenisch = new google.maps.LatLng(53.546842,9.8739);
	var latlng_volkspark = new google.maps.LatLng(53.5834,9.9017);
	var latlng_kiesgrube = new google.maps.LatLng(53.57804,9.7808);
	// var latlng = new google.maps.LatLng(53.5509709, 10.000693100000035);
	// Set up the map    
	var mapOptions = {      
		center: latlng,     
		zoom: 12,
		disableDefaultUI: false,    
		mapTypeId: google.maps.MapTypeId.ROADMAP,      
		streetViewControl: false    
	};
	map = new google.maps.Map(document.getElementById('map'), mapOptions);
	
	var image = new google.maps.MarkerImage('./img/icon.png',
	      // This marker is 20 pixels wide by 32 pixels tall.
	      new google.maps.Size(20, 20),
	      // The origin for this image is 0,0.
	      new google.maps.Point(0,0),
	      // The anchor for this image is the base of the flagpole at 0,32.
	      new google.maps.Point(0, 26));
	
	var marker_jenisch = new google.maps.Marker({
	        position: latlng_jenisch,
	        map: map,
	        title: "Jenischpark",
	    });
	
	var marker_volkspark = new google.maps.Marker({
	        position: latlng_volkspark,
	        map: map,
	        title: "Volkspark",
	    });
	
	var marker_kiesgrube = new google.maps.Marker({
	        position: latlng_kiesgrube,
	        map: map,
	        title: "Kiesgrube",
	    });
	
	
	// We get the map's default panorama and set up some defaults.    
	// Note that we don't yet set it visible.    
	panorama = map.getStreetView();
	panorama.setPosition(latlng);
	panorama.setPov({
		heading: 173.54,
		zoom: 0.7,
		pitch: 20
	});
}  


















