/**
 * @author stefan.schult
 * @author steffen.rosskamp
 * @id $Id: functions.js 283 2010-02-24 16:42:10Z stefan.schult $
 */
var isStartPage = false;
var isIe6 = jQuery.browser.msie && jQuery.browser.version === '6.0';

function init() {
	var searchInp = $('#searchInp')[0];
	if(searchInp) {
		var label = $(searchInp).parent().find('label');
		$(label).click(function(){
			$(this).addClass('inv');
		});
		$(searchInp).blur(function(){
			if(this.value === ""){
				$(label[0]).removeClass('inv');
			}
		});
	}
	var $metaArrivalLis = $('#metaArrival li');
	$metaArrivalLis.hover(
		function(){
			$(this).addClass("hovered");
			$($(this).parents()[0]).addClass("hoveredChild");
			$metaArrivalLis.each(function(){
				if(!$(this).hasClass("hovered")){
					$(this).css('opacity', 0.33);
				}
			});
		},
		function(){
			$($(this)).removeClass("hovered");
			$($(this).parents()[0]).removeClass();
			$metaArrivalLis.css('opacity', 1);
		}
	);
	if(!isIe6){
		$('#linktoCch')
			.hover(
				function(){
					var img = $($('img', $(this))[0]);
					img[0].src = img.attr("hover");

				},
				function(){
					var img = $($('img', $(this))[0]);
					img[0].src = img.attr("normal");
				}
			)
			.each(function(){
				var img = $($('img', $(this))[0]);
				img.attr("normal", img[0].src);
				img.attr("hover", img[0].src.substring(0, img[0].src.length-5) + "1.png");
			});
	}
	$('#calenderOfEvents .exhibitions h4').click(function(){
		$(this).toggleClass('expanded');
		var p = $(this).parent();
		var gp = null;
		if(isStartPage){
			gp = $($(this).parents()[1]);
		} else {
			gp = $($(this).parents()[3]);
		}
		$('div', p).toggleClass('inv');
		gp.css('z-index', (gp.css('z-index')>100 ? 3 : 500));
	});
	$('div.vcard').each(function(){
		$('div.vcardBlock div.small', $(this)).equalOffsetTop();
	});
	$("a.flipbook").fancybox({ 
		'width': '100%',
		'height': '100%',
		'overlayOpacity':0.6,
		'hideOnContentClick': false,
		'type' : 'iframe',
		'callbackOnClose': function() {
			$("#fancy_content").empty();
		}
	});

	// Plugins
	$('.faqMod').faq();
	$('.expanders').expanders();
	$('.slideshow').slideshow();
	$('.videoPlayer').video();
	$('.inputCheckboxMod .inputTextMod input, .inputCheckboxMod .inputTextMod select').additionalInput();
	$('.cText a.extern').externLinks();
	$('textarea[class^="maxlength"]').textMaxlength();
	$('.datepickerMod .inputs').datepicker();
	$('.sliderMod').slider();
	//initPrettyPhoto();
}

function initPrettyPhoto(){
	var lang = (function(){
		var l = $("html").attr('lang');
		return (l === "") ? "de" : l;
	}());
	var local = {
		en: {
			close: "Close Window",
			next: "next",
			previous: "previous",
			expand: "Expand",
			expandTitle: "Expand the image"
		},
		de: {
			close: "Fenster schliessen",
			next: "vor",
			previous: "zurück",
			expand: "vergrößern",
			expandTitle: "Inhalt vergrößern"
		}
	};
	//	$("a[rel^='prettyPhoto']").prettyPhoto();
	$("a[rel^='prettyPhoto']").prettyPhoto({
		animationSpeed: 'normal', /* fast/slow/normal */
		padding: 40, /* padding for each side of the picture */
		opacity: 0.8, /* Value betwee 0 and 1 */
		showTitle: false, /* true/false */
		allowresize: true, /* true/false */
		counter_separator_label: ' / ', /* The separator for the gallery counter 1 "of" 2 */
		theme: 'light_square light_square_'+lang, /* light_rounded / dark_rounded / light_square / dark_square */
		localize: local[lang],
		callback: function(){}
	});
}

$(init);
