// JavaScript Document
/*
-----------------------------------------------
/ Equalize height of the Graphic Teasers on the same line
-----------------------------------------------
*/ 

jQuery.noConflict();


jQuery(document).ready(function () {



	jQuery(".btnSendToFriend").click(function () {



		var iframeLink = jQuery(".btnSendToFriend").attr("href");
		jQuery("body").prepend(' <div class="tellAFriendTransparentBk2"><div class="tellAFriendTransparentBk">  </div> </div> <div class="tellAFriendWrapperIframe"> <iframe width="380" height="518" src="#" style="border: medium none;" frameborder="0"> test</iframe> </div>')
		jQuery(".tellAFriendCloseWindow").show();


		jQuery(".tellAFriendWrapperIframe iframe").attr("src", iframeLink);
		return false;
	});


	jQuery(".tellAFriendCloseWindow").click(function () {
		jQuery(".tellAFriendTransparentBk2, .tellAFriendWrapperIframe").remove();
		jQuery(".tellAFriendCloseWindow").hide();
	});

	/*
	jQuery("#date1").datepicker({showOn: 'button', firstDay: 1, dateFormat: 'dd-mm-yy', buttonImage: '/images/icon_calendar.gif', buttonImageOnly: true});
	jQuery("#date2").datepicker({showOn: 'button', firstDay: 1,  dateFormat: 'dd-mm-yy', buttonImage: '/images/icon_calendar.gif', buttonImageOnly: true});
	*/

	/*jQuery('#date1').datePicker();
	jQuery('#date2').datePicker();*/
	jQuery('#fc').css('z-index', '2000');


	jQuery(function () { jQuery('.teaserWideImage, .teaserImagePriceNumber, .teaserMediumMagazinePhoto, .teaserWideImageTextMedia, .teaserGraphicMedia, .tellAFriendTransparentBk2, .tellAFriendWrapperIframe, .searchFieldsWrap, #mainMenu div').pngFix(); });


	//	jQuery("#mainMenu").hover(function () {
	//		jQuery("#mainMenu > div").stop().animate({ height: "290px" }, 500);
	//	}, function () {
	//		jQuery("#mainMenu > div").stop().animate({ height: "44px" }, 500);

	//	});

	jQuery(function () {
		jQuery("#mainMenu li").children("ul").hide();
	});

	jQuery("#mainMenu, #mainMenu li").hover(function () {
		jQuery(this).addClass("hover");

		//		var child = jQuery(this).children("ul");

		//		var width = child.width();

		//		if (jQuery(this).hasClass("firstChild")) {
		//			child.css("background", "url(../../../images/menu_expanded_bk_new.png) no-repeat left 0");
		//			child.css("left", "-11px");
		//			child.css("position", "absolute");
		//			child.css("width", "116px");
		//			child.height(247);
		//		}
		//		else if (jQuery(this).hasClass("lastChild")) {
		//			child.height(247);
		//			child.css("background", "url(../../../images/menu_expanded_bk_new.png) no-repeat right 0px");
		//		}
		//		else {
		//			child.height(247);
		//			child.css("background", "url(../../../images/menu_expanded_bk_new.png) no-repeat center 0px");
		//		}


		jQuery(this).children("ul").show();
	}, function () {
		jQuery(this).removeClass("hover");
		jQuery(this).children("ul").hide();
	});


	if (jQuery.browser.msie && jQuery.browser.version <= 6) {

		jQuery("#mainMenu li:first").hover(function () {
			jQuery(this).addClass("hoverFirstChild");
		}, function () {
			jQuery(this).removeClass("hoverFirstChild");
		})

		if (jQuery("#mainMenu li:first").hasClass("activePage")) {
			jQuery("#mainMenu li:first").addClass("activePageFirstChild");
		}

	}
	/*
	-----------------------------------------------
	ONLINE BOOKING FORM PAGE
	-----------------------------------------------
	*/

	jQuery(".onlineBookingFormRooms").hide();

	jQuery("#oneWaytripType").click(function () {

		if (jQuery("#oneWaytripType:checked").length == 1) {
			jQuery(".onlineBookingFormRetur").hide();
			jQuery("#onlineBookingFormFlyMed").hide();
		} else {
			jQuery(".onlineBookingFormRetur").show();
			jQuery("#onlineBookingFormFlyMed").show();
		}

	});

	jQuery("#ReturntripType").click(function () {

		if (jQuery("#ReturntripType:checked").length == 1) {
			jQuery(".onlineBookingFormRetur").show();
			jQuery("#onlineBookingFormFlyMed").show();
		} else {
			jQuery(".onlineBookingFormRetur").hide();
			jQuery("#onlineBookingFormFlyMed").hide();
		}

	});

	jQuery("#bookhotel").click(function () {

		if (jQuery("#bookhotel:checked").length == 1) {
			jQuery(".onlineBookingFormRooms").show();
		} else {
			jQuery(".onlineBookingFormRooms").hide();
		}

	});


	for (i = 1; i <= 8; i++) {
		jQuery(".onlineBookingFormChildAge:first").clone(true).insertAfter(jQuery(".onlineBookingFormChildAge:last")).children("select").attr("id", "age" + i + "DropDown").attr("name", "age" + i + "DropDown");

	}
	jQuery(".onlineBookingFormChildAge").hide();



	jQuery("#childDropDown").change(function () {
		var nrChildren = Number(jQuery("#childDropDown option:selected").val());
		jQuery(".onlineBookingFormChildAge").hide();
		for (var i = 0; i < nrChildren; i++) {
			jQuery(".onlineBookingFormChildAge").eq(i + 1).show();
		}

	});

	/*
	-----------------------------------------------
	/ ONLINE BOOKING FORM PAGE
	-----------------------------------------------
	*/




	/*
	-----------------------------------------------
	Tabs on booking machine
	-----------------------------------------------
	*/

	var qs = (function (a) {
		if (a == "") return {};
		var b = {};
		for (var i = 0; i < a.length; ++i) {
			var p = a[i].split('=');
			if (p.length != 2) continue;
			b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
		}
		return b;
	})(window.location.search.substr(1).split('&'));


	jQuery(".bookingMachines div").hide();
	var ShowTab = 2;

	var ShowTabValue = qs["ShowTab"];
	if (ShowTabValue)
		ShowTab = ShowTabValue;

	jQuery(".bookingMachines .bookingMachinesTab" + ShowTab).show();

	jQuery(".bookingMachinesTabs li a img").click(function () {
		jQuery(".bookingMachines").children().hide();

		jQuery(".bookingMachinesTabs li").removeClass("active");
		jQuery(this).parent().parent().addClass("active");

		var pos = jQuery(this).parent().attr("rel")
		jQuery(".bookingMachines .bookingMachinesTab" + pos).show();
	});

	jQuery(".bookingMachinesTabs li").hover(function () {
		jQuery(this).addClass("active2");
	}, function () {
		jQuery(this).removeClass("active2");

	})

	/*
	-----------------------------------------------
	teaserGraphic ANIMATION
	-----------------------------------------------
	*/


	var teaserGraphicNr = jQuery(".teaserGraphicAnimList .teaserGraphic").length;


	jQuery(".teaserGraphicAnimList .teaserGraphic").append('<ul class="teaserGraphicNavigation"></ul>')
	for (var i = 0; i < teaserGraphicNr; i++) {
		jQuery(".teaserGraphic .teaserGraphicNavigation").append("<li>&nbsp;</li>")
	}

	moveImagesUp();

	/* function that moves the image up so that the bottom is shown */
	function moveImagesUp() {
		jQuery(".teaserGraphicMedia img").each(function (index) {
			var imgHeight = jQuery(this).height();

			var parent = jQuery(this).parent(".teaserGraphicMedia").height();

			jQuery(this).css('marginTop', parent - imgHeight + "px");
		});
	}


	var timeOutDelay;
	var teaserGraphicCurentPos = 0;
	var teaserGraphicCurentX = 0;
	var teaserGraphicWidth = 236;

	jQuery(".teaserGraphicNavigation li").click(function () {
		teaserGraphicCurentPos = jQuery(".teaserGraphicNavigation li").index(this) % teaserGraphicNr;
		teaserGraphicAnimation();
		intervalTrigger();
	})

	jQuery(".teaserGraphicNavigation").each(function (i) {		// add green bullet for the active li
		jQuery(this).children("li:first").addClass("activeTeaser");
	});


	function teaserGraphicAnimation() {

		jQuery(".teaserGraphicNavigation").each(function (i) {		// add green bullet for the active li
			jQuery(this).children("li").removeClass("activeTeaser").eq(teaserGraphicCurentPos).addClass("activeTeaser");
		});


		jQuery(".teaserGraphicAnimList").animate({
			left: teaserGraphicCurentPos * (-teaserGraphicWidth) + "px"
		}, 1000, function () {
		});

		if (teaserGraphicCurentPos < teaserGraphicNr - 1) {
			teaserGraphicCurentPos++;
			teaserGraphicCurentX = teaserGraphicCurentPos * (-teaserGraphicWidth);
		} else {
			teaserGraphicCurentPos = 0;
			teaserGraphicCurentX = 0;
		}

		moveImagesUp();
	}




	function intervalTrigger() {
		clearInterval(timeOutDelay);
		timeOutDelay = setInterval(teaserGraphicAnimation, 4000);
	};

	intervalTrigger();

	jQuery(".teaserGraphicAnimList .teaserGraphic").hover(function () {
		clearInterval(timeOutDelay);
	}, function () {
		intervalTrigger();
	})

	/*
	
	setInterval ( teaserGraphicAnimation(), 2000 );
	
	
	jQuery(".teaserGraphicAnimList").animate({ 
	marginLeft:  teaserGraphicCurentX+"px"
	}, 1000, "linear", function(){alert("all done");} );

	
	*/


	/*
	jQuery(".teaserGraphicAnimList").animate({ 
	marginLeft:  teaserGraphicCurentX+"px"
	},1100 ).animate({ 
	opacity: 1
	}, 1000, function(){
		
	if (teaserGraphicCurentPos < teaserGraphicNr){
	teaserGraphicCurentPos ++;		
	teaserGraphicCurentX = teaserGraphicCurentX - 236;

	}else{
	teaserGraphicCurentPos = 1;
	teaserGraphicCurentX = 0;
	}
		
	teaserGraphicAnimation()
	});
	*/


	/*
	-----------------------------------------------
	/ teaserGraphic ANIMATION
	-----------------------------------------------
	*/

	googleTracker();


	function googleTracker() {

		var src = jQuery("#iFrameSrc").text();

		_gaq.push(function () {
			var pageTracker = _gat._getTrackerByName();
			var iframe = document.getElementById('idTopFrame');
			iframe.src = pageTracker._getLinkerUrl(src);
		});
	}


});







