
function responsiveRibbon() {

	var pageWidth = $(window).width();
	var deviceAgent = navigator.userAgent.toLowerCase();
	var iOSdetected = deviceAgent.match(/(iphone|ipod|ipad|android)/);

	if(pageWidth<=480 && iOSdetected) {
		$("#innerBody").addClass("mobile");		
		$("#innerBody").removeClass("desktop");		
	} else {
/* 		$('#thumbs').superbgimage().show(); */
		$("#innerBody").removeClass("mobile");		
		$("#innerBody").addClass("desktop");		
		var pageHeight = $(window).height();
		if($("#innerBody").hasClass("lower")) {
			// threshold = 780;
			var lowerContentHeight = $("#lowerContent").height();

			threshold = (lowerContentHeight * 2) + 180; // 100 = ribbon
			if (pageHeight < threshold) {
/* 			alert(lowerContentHeight) */
				// offset = threshold - pageHeight;
				ribbonPos = lowerContentHeight +40;
				$(".desktop #ribbon").css({"marginTop":0,"top":"auto","bottom":ribbonPos});
				$(".desktop #ribbonShadow").css({"marginTop":0,"top":"auto","bottom":ribbonPos-84});
				$(".desktop #lowerContent").css({"top":"auto","bottom":0});
		
				
			} else {
				$(".desktop #ribbon").css({"marginTop":-50,"top":"50%","bottom":"auto"});
				$(".desktop #ribbonShadow").css({"marginTop":-133,"top":"50%","bottom":"auto"});
				$(".desktop #lowerContent").css({"top":"50%"});
			}
		
		} else {
			threshold = 600;
			if (pageHeight < threshold) {
				// offset = threshold - pageHeight;
				$(".desktop #ribbon").css({"marginTop":0,"top":250});
				$(".desktop #ribbonShadow").css({"marginTop":0,"top":166});
				$(".desktop #upperContent").css({"marginTop":0,"top":0,"bottom":"auto"});
			} else {
				$(".desktop #ribbon").css({"marginTop":-50,"top":"50%","bottom":"auto"});
				$(".desktop #ribbonShadow").css({"marginTop":-133,"top":"50%","bottom":"auto"});
				$(".desktop #upperContent").css({"top":"50%","marginTop":-300});
			}
		}
	}


}




$(document).ready(function() {
		
		responsiveRibbon();
		//	responsiveRibbon();
		$(window).resize(function() {
			responsiveRibbon();
		});




/* too slow atm */
/*		$("#gallery").animate({"opacity":1,"marginLeft":0}, { duration: 1000, easing: "linear", queue: false} ); */
/*
		$("#gallery").animate({"opacity":0}, 125, "linear", function() {
			$("#gallery").animate({"opacity":1,"marginLeft":0}, 125, "linear", function() {
				$("#upperContent").animate({"marginTop":-312}, { duration: 500, easing: "linear", queue: false} );
				$("#lowerContent").animate({"marginTop":12}, { duration: 500, easing: "linear", queue: false} );
			});
		});
*/


		
			
		var myloc = String(document.location);
		if ( myloc.search(/pages\/de\/.+/) != -1 ) { mfcurrentlanguage="de";	}
		if ( myloc.search(/pages\/en\/.+/) != -1 ) { mfcurrentlanguage="en";	}
		if ( myloc.search(/pages\/fr\/.+/) != -1 ) { mfcurrentlanguage="fr";	}

		$('#logo').bind("click", function() {
 			document.location = "/pages/"+mfcurrentlanguage+"/home";
 		});



// DISABLE accidental selection of text except for contact pages
/*

	if (  myloc.search(/blumenversand\/.+/) == -1 && myloc.search(/mf\/.+/) == -1 &&  myloc.search(/kontakt\/.+/) == -1 && myloc.search(/contact\/.+/) == -1 ) { 

		if (typeof document.onselectstart!="undefined") {
			document.onselectstart=new Function ("return false");
		}else{
			document.onmousedown=new Function ("return false");
			document.onmouseup=new Function ("return true");
		}
	}
*/



	// enable App-Like Behaviour on iPad
	var deviceAgent = navigator.userAgent.toLowerCase();
	var iOSdetected = deviceAgent.match(/(iphone|ipod|ipad)/);
	
	if(iOSdetected) {
		$('a').bind("click", function() {
			if ($(this).parent().hasClass("level1")) {
			// dont't execute click events in level1 (touch!)
			} else {
			
				if (
					($(this).attr("href")!="#") && 
					($(this).attr("href").search(/javascript.+/) == -1 )
					) 
				{
					var oldref = $(this).attr("href");
					$(this).attr("href","javascript:document.location='"+oldref+"';");
				}
			}
		});
	}


/*
	
	$('.subMenu ul.navi li.inactive, #navigation ul.navi li.inactive, .metanavigation ul.navi li.inactive').bind("mouseenter", function() {
		var self = this;
		$(self).find("a").animate({"color":"#000"}, { duration: 250, easing: "linear", queue: false} );
	}).bind("mouseleave", function() {
		var self = this;
		$(self).find("a").animate({"color":"#666"}, { duration: 125, easing: "linear", queue: false} );
	});
*/

	$('.subMenu ul.navi li.inactive a, #navigation ul.navi li.inactive a, .metanavigation ul.navi li.inactive a').bind("mouseenter", function() {
		var self = this;
		$(self).animate({"color":"#000"}, { duration: 250, easing: "linear", queue: false} );
	}).bind("mouseleave", function() {
		var self = this;
		$(self).animate({"color":"#666"}, { duration: 250, easing: "linear", queue: false} );
	});

/*
		$('#scrollDown').bind("click", function() {
			    var current = $('#scrollBox').scrollTop();
			    current = current + 25;
			    $('#scrollBox').scrollTop(current);
		});
		$('#scrollUp').bind("click", function() {
			    var current = $('#scrollBox').scrollTop();
			    current = current - 25;
			    if (current <= 0 ) { current = 0 };
			    $('#scrollBox').scrollTop(current);
		});
*/
var currentFiliale = 1;
		$('.filiale').bind("click", function() {
			var self = this;
//					alert($(self).attr("id"));
/* alert(currentFiliale); */
			if ($(self).attr("id")=="filiale894" && currentFiliale!=1) { $('#thumbs').gotoSlide(1);currentFiliale=1; } // nonntaler
			if ($(self).attr("id")=="filiale949" && currentFiliale!=2) { $('#thumbs').gotoSlide(3);currentFiliale=2;  } // visavis
			if ($(self).attr("id")=="filiale950" && currentFiliale!=3) { $('#thumbs').gotoSlide(5);currentFiliale=3;  } // parsch
			if ($(self).attr("id")=="filiale963" && currentFiliale!=4) { $('#thumbs').gotoSlide(2);currentFiliale=4;  } // getreidegasse
			if ($(self).attr("id")=="filiale951" && currentFiliale!=5) { $('#thumbs').gotoSlide(4);currentFiliale=5;  } // anif
			if ($(self).attr("id")=="filiale952" && currentFiliale!=6) { $('#thumbs').gotoSlide(6);currentFiliale=6;  } // europark
			if ($(self).attr("id")=="filiale1220" && currentFiliale!=7) { $('#thumbs').gotoSlide(7);currentFiliale=7;  } // Berchtesgarden
			if ($(self).attr("id")=="filiale1192" && currentFiliale!=8) { $('#thumbs').gotoSlide(8);currentFiliale=8;  } // Berchtesgarden

		});
		
		
	var speed = 125;
	// marginTop ist jew. (-1 * ((anzahl menüpunkte +1) * 25))
	// height ist jew. (-1 * ((anzahl menüpunkte +1) * 25))


	
	$('.desktop #entry_gaertnerei').bind("mouseenter", function() {
		var pageHeight = $(window).height();
		if (pageHeight>600) {
			var $allListElements = $('#subMenu_de_gaertnerei.subMenu li');
			var numberOfEntries = $allListElements.size();
			$(".subMenu").animate({"opacity":0,"marginTop":0,"zIndex":0,"height":0}, { duration: speed, easing: "linear", queue: false} );
			$("#subMenu_de_gaertnerei.subMenu").animate({"opacity":1,"marginTop":(-1*((numberOfEntries + 3) * 25)),"zIndex":4,"height":numberOfEntries * 25}, { duration: speed, easing: "linear", queue: false} );
			$("#fakeMenuShadow").animate({"opacity":1,"marginTop":-50,"right":$("#subMenu_de_gaertnerei.subMenu").css("right")}, { duration: speed, easing: "linear", queue: false} );
		}

	});

	$('.desktop #entry_blumen').bind("mouseenter", function() {
		var pageHeight = $(window).height();
		if (pageHeight>600) {
			var $allListElements = $('#subMenu_de_blumen.subMenu li');
			var numberOfEntries = $allListElements.size();
			$(".subMenu").animate({"opacity":0,"marginTop":0,"zIndex":0,"height":0}, { duration: speed, easing: "linear", queue: false} );
			$("#subMenu_de_blumen.subMenu").animate({"opacity":1,"marginTop":(-1*((numberOfEntries + 3) * 25)),"zIndex":4,"height":numberOfEntries * 25}, { duration: speed, easing: "linear", queue: false} );
			$("#fakeMenuShadow").animate({"opacity":1,"marginTop":-50,"right":$("#subMenu_de_blumen").css("right")}, { duration: speed, easing: "linear", queue: false} );
		}
	});

	$('.desktop #entry_anlaesse').bind("mouseenter", function() {
		var pageHeight = $(window).height();
		if (pageHeight>600) {
			var $allListElements = $('#subMenu_de_anlaesse.subMenu li');
			var numberOfEntries = $allListElements.size();
			$(".subMenu").animate({"opacity":0,"marginTop":0,"zIndex":0,"height":0}, { duration: speed, easing: "linear", queue: false} );
			$("#subMenu_de_anlaesse.subMenu").animate({"opacity":1,"marginTop":(-1*((numberOfEntries + 3) * 25)),"zIndex":4,"height":numberOfEntries * 25}, { duration: speed, easing: "linear", queue: false} );
			$("#fakeMenuShadow").animate({"opacity":1,"marginTop":-50,"right":$("#subMenu_de_anlaesse.subMenu").css("right")}, { duration: speed, easing: "linear", queue: false} );
		}
	});
	
	$('.desktop #entry_in-exterior').bind("mouseenter", function() {
		var pageHeight = $(window).height();
		if (pageHeight>600) {
			var $allListElements = $('#subMenu_de_in-exterior.subMenu li');
			var numberOfEntries = $allListElements.size();
			$(".subMenu").animate({"opacity":0,"marginTop":0,"zIndex":0,"height":0}, { duration: speed, easing: "linear", queue: false} );
			$("#subMenu_de_in-exterior.subMenu").animate({"opacity":1,"marginTop":(-1*((numberOfEntries + 3) * 25)),"zIndex":4,"height":numberOfEntries * 25}, { duration: speed, easing: "linear", queue: false} );
			$("#fakeMenuShadow").animate({"opacity":1,"marginTop":-50,"right":$("#subMenu_de_in-exterior.subMenu").css("right")}, { duration: speed, easing: "linear", queue: false} );
		}
	});

	$('.desktop #entry_begruenung').bind("mouseenter", function() {
		var pageHeight = $(window).height();
		if (pageHeight>600) {
			var $allListElements = $('#subMenu_de_begruenung.subMenu li');
			var numberOfEntries = $allListElements.size();
			$(".subMenu").animate({"opacity":0,"marginTop":0,"zIndex":4,"height":0}, { duration: speed, easing: "linear", queue: false} );
			$("#subMenu_de_begruenung.subMenu").animate({"opacity":1,"marginTop":(-1*((numberOfEntries + 3) * 25)),"zIndex":4,"height":numberOfEntries * 25}, { duration: speed, easing: "linear", queue: false} );
			$("#fakeMenuShadow").animate({"opacity":1,"marginTop":-50,"right":$("#subMenu_de_begruenung.subMenu").css("right")}, { duration: speed, easing: "linear", queue: false} );
		}
	});

	$('.desktop #catcherInTheRye, .desktop #upperContent, .desktop #lowerContent, .desktop .metanavigation li').bind("mouseenter", function() {
		$(".subMenu").animate({"opacity":0,"marginTop":-100}, { duration: speed, easing: "linear", queue: false} );
		$("#fakeMenuShadow").animate({"opacity":0,"marginTop":-45}, { duration: speed, easing: "linear", queue: false} );
		$("#upperContent").animate({"opacity":1,"marginTop":-300}, { duration: speed, easing: "linear", queue: false} );
	});



	$('#siteservice').bind("mouseenter", function() {
		var self = this;
		$(self).find("img").animate({"opacity":1}, { duration: 250, easing: "linear", queue: false} );
	}).bind("mouseleave", function() {
		var self = this;
		$(self).find("img").animate({"opacity":.5}, { duration: 250, easing: "linear", queue: false} );
	});


	$('#thumbs a:not(.activeslide)').bind("mouseenter", function() {
		var self = this;
/* 		$(self).find("img").animate({"width":80}, { duration: 250, easing: "linear", queue: false} ); */
		$(self).animate({"opacity":1,"width":80}, { duration: 250, easing: "linear", queue: false} );
	}).bind("mouseleave", function() {
		var self = this;
/* 		$(self).find("img").animate({"opacity":1}, { duration: 250, easing: "linear", queue: false} ); */
		$(self).animate({"opacity":.5,"width":30}, { duration: 250, easing: "linear", queue: false} );
	});



	$('#close').bind("click", function() {
		var self = this;
/*
		$("#centerContent").animate({"opacity":0.2,"top":"60%","marginTop":0}, 250, "linear", function() {
			$("#catcherInTheRye").animate({"opacity":0}, { duration: 250, easing: "linear", queue: false} );
			$("#centerContent").css({"display":"none"}); 
		});
*/
		$("#centerContent").animate({"opacity":0.2}, 250, "linear", function() {
			$("#centerContent").css({"display":"none"}); 
		});
	});


	$('.de_home_kontakt-filialen #lowerContent .textBox').bind("mouseenter", function() {
		var self = this;
		$(self).find("h1").animate({"color":"#e53e16"}, { duration: 250, easing: "linear", queue: false} );
		$(self).find("b,strong").animate({"color":"#e53e16"}, { duration: 250, easing: "linear", queue: false} );
	}).bind("mouseleave", function() {
		var self = this;
		$(self).find("h1").animate({"color":"#333"}, { duration: 250, easing: "linear", queue: false} );
		$(self).find("b,strong").animate({"color":"#333"}, { duration: 250, easing: "linear", queue: false} );
	});




});
