var pageContentHeight=false;
var scrollDiv=false;


var resizeContent = function() {

	var windowheight=jQuery(window).height();
	var contentheight = windowheight - 230;

	if (windowheight<500) return;
	
	if (!pageContentHeight) pageContentHeight=jQuery('#content').height();
	

	jQuery('#content').height(contentheight).css('overflow','hidden');
	jQuery('#content').css('position','fixed').css('width',1000);
	jQuery('#contentscroller').css('position','absolute');
	jQuery('#contentscroller').height(pageContentHeight);
		
	jQuery('#navigation').css('position','fixed');
	jQuery('#navigation').css('top',contentheight+20);

	
	if (!scrollDiv) scrollDiv=jQuery('<div></div>');
	jQuery('body').append(scrollDiv);
	scrollRatio=contentheight/pageContentHeight;
	
	scrollDiv.height(windowheight/scrollRatio);
	
	jQuery(window).scroll(function() {

		var scrollTop = jQuery(this).scrollTop();
				
	//	jQuery('#content').css('top',scrollTop);
		jQuery('#contentscroller').css('top',-scrollTop);
	
		
		//jQuery('#navigation').css('top',scrollTop+20+contentheight);
		
		
	})
	return;
			
};

var winzerFormsTransform = function() {
	
	$('select.sfwinzer_grapetypeselect').change(function() {
		$(this).parent()[0].submit();
	});
	$('select#sfwinzer_ortselect').change(function() {
		$(this).parent()[0].submit();
	});
	
	
}

var openInfoWindow=false;
var actMarker=false;

var winzermap = function(center) {
	
	var south=90;
	var north=0;
	var east=-180
	var west=180;
	
	var map = new google.maps.Map(document.getElementById("winzermap"),{
		center: center,
		zoom: 13,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	});
	
	$.each(pois,function(i,poi) {
		
		var position = new google.maps.LatLng(poi.lat,poi.lon);
		
		west=Math.min(west,position.lng());
		east=Math.max(east,position.lng());
		north=Math.max(north,position.lat());
		south=Math.min(south,position.lat());
		
		var marker = new google.maps.Marker({
			position: position, 
			map: map,
			title:poi.title
		});
		marker.myContent=poi.html;
		
		var infowindow=new google.maps.InfoWindow({
		    content: marker.myContent
		});

		google.maps.event.addListener(infowindow,'closeclick',function() {
			if (openInfoWindow) openInfoWindow = false;
			actMarker = false;
		});

		google.maps.event.addListener(marker, 'click', function() {
			if (openInfoWindow) {
				openInfoWindow.close();
				openInfoWindow = false;
			};

			infowindow.open(map,marker);
			openInfoWindow=infowindow;
		});	
	});	
	if (pois.length>1)
	map.fitBounds(new google.maps.LatLngBounds(
		new google.maps.LatLng(south,west),
		new google.maps.LatLng(north,east)
	));
}

var prepareClickEnlarge = function() {
	
	$('.lightbox,a[target=lightbox]').colorbox({
		maxWidth: '90%',
		scalePhotos: false
	});
	
};


var colorBoxLanguage = { 
	current: "Bild {current} von {total}",
	previous: "zurück",
	next: "weiter",
	close: "Schließen"
};

jQuery(document).ready(function() {
	resizeContent();
	jQuery(window).resize(function() {
		resizeContent();
	});
	
	var galleryClasses={};
	var galleryClassesArray=[]
	jQuery("a.tx_shfrgallery_pi1").each(function() {
		var myClass=jQuery(this).attr('rel');
		if (!galleryClasses[myClass]) {
			galleryClasses[myClass]=true;
			galleryClassesArray.push(myClass);
		};
	});
	for (var i=0;i<galleryClassesArray.length;i++) {
		jQuery("a[rel='"+galleryClassesArray[i]+"']").colorbox(colorBoxLanguage);
	};
	
	jQuery("ul.innerfade").innerfade({
		speed: 3000,
		timeout: 6000
	});
	
	winzerFormsTransform();
	
	prepareClickEnlarge();
});


