function fbs_click() {
    u = location.href;
    t = document.title;
    window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
    return false;
}

//schattieruung anpassen
function adaptShadow() {
	hContent = $('#main').height();
	$('#left').height(hContent);
}

//fader bei image gsatzeln
function fadeTrailer() {
	var next = $('div.boxInner_change:visible').next();
	if(next.size()==0) {
		$('div.boxInner_change:visible').hide();
		$('div.boxInner_change:first').show();
	} else {
		$('div.boxInner_change:visible').hide().next().show();
	}
}

function loadProduct (href, desc) {
	window.location.hash = desc;
	$('#produktContent').load(href, {cid:1}, function() {
		$(this).find("a[href$='jpg'], a[href$='JPG'], a[href$='jpeg'], a[href$='JPEG'], a[href$='png'], a[href$='PNG'], a[href$='gif'], a[href$='GIF']").fancybox();
		adaptShadow();
	});
}

$(document).ready( function() {

	//IMG ohne alt Text füllen
	$("img[alt='']").attr('alt','Cranpool');
	
	// fancybox
	$("a[href$='jpg'], a[href$='JPG'], a[href$='jpeg'], a[href$='JPEG'], a[href$='png'], a[href$='PNG'], a[href$='gif'], a[href$='GIF']").fancybox();
	$("table a[href^='mailto']").each(function() {
		mailadress = $(this).attr('href');
		mail = mailadress.match(/\b[\w\.-]+@[\w\.-]+\.\w{2,4}\b/g);
		mail = mail[0];
		$(this).attr('href','/_include/site/empty.php?mail='+mail);
	});
	$("table a[href*='/oeffnungszeiten_center/'], table a[href^='/_include/site/empty.php']").fancybox({height:480, width:390, autoDimensions:false, padding:15});
	
	indexText = $("#iFullscreen #text").text();
	// navigation mouse hover
	$('#iFullscreen #navigation a').hover(function() {
		newSrc = $(this).attr("icon");
		newSlogan = $(this).attr("href");
		box = $('#iBox img:first');
		box.attr('icon',box.attr('src'));
		box.attr("src", newSrc);
		if($("div[rel*='"+newSlogan+"']").size()>0) {
			var changeText = $("div[rel*='"+newSlogan+"']").text();
			$("#iFullscreen #text").text(changeText);
		}
	}, function() {
		newSrc = $('#iBox img:first').attr("icon");
		$('#iBox img:first').attr("src", newSrc);
		$("#iFullscreen #text").text(indexText);
	});
	
	// subnavigation mouse hover
	if($('#iBox img').size()>0) {
		$('#subnavigation a').hover(function() {
			newSrc = $(this).attr("icon");
			box = $('#iBox img:first');
			box.attr('icon',box.attr('src'));
			box.attr("src", newSrc);
		}, function() {
			newSrc = $('#iBox img:first').attr("icon");
			$('#iBox img:first').attr("src", newSrc);
		});
	}
	
	// korrekturen pfeilboxen
	$("ul").each(function(e,d) {
		if($(d).parent('.boxInner').size()>0) {
			$(d).parent('.boxInner').css({backgroundImage:"none", paddingLeft:"0px"});
		}
	});

	// produkt navigation
	navigationArray = new Array();
	doctypeArray = new Array(42,49,43);
	for (var i = 0; i < doctypeArray.length; ++i) {
		navigationArray[i] = $("#produktNavigation a[rel='"+doctypeArray[i]+"']").remove();
	}
	for (var i = 0; i < navigationArray.length; ++i) {
		$('#produktNavigation').append(navigationArray[i]);
	}
	
	$('#produktNavigation a').live('click', function() {
		href = $(this).attr('href');
		desc = $(this).text();
		$('#produktNavigation a').removeAttr('id');
		$(this).attr('id','active');
		loadProduct(href, desc);
		return false;
	});

	// produkt navigation am start abfangen
	wHash = window.location.hash.substr(1,90);
	if(wHash.length>3) {
		$("#produktNavigation a:contains('"+wHash+"')").trigger('click');
	}
	
	inline = $.trim($('#whiteSideBox').text());
	if(inline=='' && $('#whiteSideBox a img').size()==0) {
		$('#whiteSideBox').remove();
	}
	
	adaptShadow();
	
	if($('div.boxInner_change').size()>1) {
		$('div.boxInner_change:gt(0)').hide();
		window.setInterval("fadeTrailer()", 3000);
	}
	
	//boxGalerie
	if($('#boxGalerie div').size()<3) {
		$('#boxGalerieUp, #boxGalerieDown').remove();
	}
	
	$('#boxGalerieUp').bind('click', function() {
		box = $('#boxGalerie');
		box.find('div:first').animate({marginTop:'-200px'}, 800, function() {
			box.find('div:lt(1)').css('margin-top','0px').remove().appendTo(box);
			$(this).css('marginTop','3px');
			$("a[href$='jpg'], a[href$='JPG'], a[href$='jpeg'], a[href$='JPEG'], a[href$='png'], a[href$='PNG'], a[href$='gif'], a[href$='GIF']").fancybox();
		});
	});
	$('#boxGalerieDown').bind('click', function() {
		box = $('#boxGalerie');
		boxes = box.find('div').size();
		boxes = boxes-2;
		box.find('div:gt('+boxes+')').remove().prependTo(box).find('div:first');
		box.find('div:first').css('marginTop','-200px').animate({marginTop:'0'}, 800, function() {
			$("a[href$='jpg'], a[href$='JPG'], a[href$='jpeg'], a[href$='JPEG'], a[href$='png'], a[href$='PNG'], a[href$='gif'], a[href$='GIF']").fancybox();
		});
	});

	$('#headPullDown').bind('click', function() {
		$('#sendAFriend').animate({height:'370px'},800, function() {adaptShadow();});
		$('#plControl').attr('src','/_images/plDown.gif');
	}); 
	
	
	//korrektur galerie zu produktgalerie
	$("li a[href*='pools'][href*='galerie'][href$='php']").each(function() {
		oldHref = $(this).attr('href');
		oldHref_cut = oldHref.lastIndexOf('/');
		newHref = oldHref.substr(0,oldHref_cut+1);
		newHref = newHref+"index.php#Galerie";
		$(this).attr('href',newHref);
	});

	//korrektur bildergalerie link btns
	$('ul.btn li:first').remove();

	// send formular service
	$("#service input.submit").live('click', function() {
		d = $("#service").serialize();
		$("#anfrage-service").load('/_include/site/contact.php', {data: d});
	});
});

