function infodestPixSelect(thumbnail, thumbnail_id, type) {
	//Hide all the selected borders
	var id_thumbnails = "#infodest_pix_thumbnails_" + type + " .infodest_pix_thumb_selected";
	$$(id_thumbnails).each(function(selected_thumbnail){
        selected_thumbnail.removeClassName("infodest_pix_thumb_selected");
    });
	
	//Add the class on the newly selected element
    $(thumbnail).addClassName("infodest_pix_thumb_selected");
    
    var thumbpath = $(thumbnail).select("img")[0].src;
    var bigpix_url = thumbpath.replace('T','B');
    
	var id_bigpix = "infodest_pix_big_" + type;
	
    var bigpix = $(id_bigpix).select("img")[0];
    
    // Fadeout the bigpix, change it's url then appear.
    new Effect.Fade(bigpix, {
        duration:0.3, 
        afterFinish : function(){
           bigpix.src = bigpix_url;
           bigpix.onload = function(){
               new Effect.Appear(bigpix, {
                   duration:0.3
               }); 
           }
        }
    });
	
	//ANALYTICS
	pageTracker._trackEvent('Carousel', 'Show image');
}

function infodestTopTabs(tab, lat, long, zoom) {
	
	//ANALYTICS
	var info_google_title;
	
	if(tab ==0)	{ info_google_title = "Prices and packages"};
	if(tab ==1)	{ info_google_title = "Region infos"};
	if(tab ==2)	{ info_google_title = "Satellite view"};
	if(tab ==3)	{ info_google_title = "Reviews"};
	
	pageTracker._trackEvent('Onglet Info Hotel', 'Click', info_google_title);
	
	if (tab == '0')
	{
		if ($('infodest_top_tabs').style.backgroundPosition != "0px 0px")
		{
			if ($('infodest_satellite').style.display == "block")
			{
				infodestTopTabsDisable();
				new Effect.toggle($('infodest_satellite'), 'Blind', {duration:0.6})
				setTimeout(function(){
					$('infodest_satellite').style.display = "none";
					$('infodest_satellite_content').style.display = "none";
					$('infodest_top_tabs').style.backgroundPosition = "0px 0px";
					new Effect.toggle($('infodest_pix_hotel'), 'Blind', {duration:0.6})
				}, 800);
				setTimeout(function(){
					$('infodest_pix_hotel').style.display = "block";
					resizeParentFrame('375');
					setTimeout(
						function()
						{
							if (window.parent.$('results_details_list').style.display == "none")
							{
								new Effect.SlideDown(window.parent.document.getElementById('results_details_list'), {duration:0.6})
								new Effect.SlideDown(window.parent.document.getElementById('results_details_otherdates'), {duration:0.6})
							}
						}
					,1200);
				},1700);
				setTimeout(function(){infodestTopTabsEnable();},3000);
			}
			else if ($('infodest_pix_region').style.display == "block")
			{
				infodestTopTabsDisable();
				new Effect.toggle($('infodest_pix_region'), 'Blind', {duration:0.6})
				setTimeout(function(){
					$('infodest_pix_region').style.display = "none";
					$('infodest_top_tabs').style.backgroundPosition = "0px 0px";
					new Effect.toggle($('infodest_pix_hotel'), 'Blind', {duration:0.6})
				}, 800);
				setTimeout(function(){
					$('infodest_pix_hotel').style.display = "block";
					resizeParentFrame('375');
					setTimeout(
						function()
						{
							if (window.parent.$('results_details_list').style.display == "none")
							{
								new Effect.SlideDown(window.parent.document.getElementById('results_details_list'), {duration:0.6})
								new Effect.SlideDown(window.parent.document.getElementById('results_details_otherdates'), {duration:0.6})
							}
						}
					,1200);
				},1700);
				setTimeout(function(){infodestTopTabsEnable();},3000);
			}
			
			else
			{
				infodestTopTabsDisable();
				$('infodest_top_tabs').style.backgroundPosition = "0px 0px";
				resizeParentFrame('375');
				setTimeout(
					function()
					{
						if (window.parent.$('results_details_list').style.display == "none")
						{
							new Effect.SlideDown(window.parent.document.getElementById('results_details_list'), {duration:0.6})
							new Effect.SlideDown(window.parent.document.getElementById('results_details_otherdates'), {duration:0.6})
						}
					}
				,1000);
				setTimeout(function(){infodestTopTabsEnable();},1700);
			}
		}
	}

	if (tab == '1')
	{
		if ($('infodest_top_tabs').style.backgroundPosition != "0px -45px")
		{
			if ($('infodest_satellite').style.display == "block")
			{
				infodestTopTabsDisable();
				new Effect.toggle($('infodest_satellite'), 'Blind', {duration:0.6})
				setTimeout(function(){
					$('infodest_satellite').style.display = "none";
					$('infodest_satellite_content').style.display = "none";
					$('infodest_top_tabs').style.backgroundPosition = "0px -45px";
					new Effect.toggle($('infodest_pix_region'), 'Blind', {duration:0.6})
				}, 900);
				setTimeout(function(){
					$('infodest_pix_region').style.display = "block";
					new Effect.SlideUp(window.parent.document.getElementById('results_details_list'), {duration:0.6})
					new Effect.SlideUp(window.parent.document.getElementById('results_details_otherdates'), {duration:0.6})
					setTimeout(function(){infodestTabs('0')}, 900);
				}, 1800);
				setTimeout(function(){infodestTopTabsEnable();},3200);
			}
			else if ($('infodest_pix_hotel').style.display == "block")
			{
				infodestTopTabsDisable();
				new Effect.toggle($('infodest_pix_hotel'), 'Blind', {duration:0.6})
				setTimeout(function(){
					$('infodest_pix_hotel').style.display = "none";
					$('infodest_top_tabs').style.backgroundPosition = "0px -45px";
					new Effect.toggle($('infodest_pix_region'), 'Blind', {duration:0.6})
				}, 900);
				setTimeout(function(){
					$('infodest_pix_region').style.display = "block";
					new Effect.SlideUp(window.parent.document.getElementById('results_details_list'), {duration:0.6})
					new Effect.SlideUp(window.parent.document.getElementById('results_details_otherdates'), {duration:0.6})
					setTimeout(function(){infodestTabs('0')}, 900);
				}, 1800);
				setTimeout(function(){infodestTopTabsEnable();},3200);
			}
			else if ($('infodest_pix_region').style.display == "block")
			{
				infodestTopTabsDisable();
				$('infodest_top_tabs').style.backgroundPosition = "0px -45px";
				new Effect.SlideUp(window.parent.document.getElementById('results_details_list'), {duration:0.6})
				new Effect.SlideUp(window.parent.document.getElementById('results_details_otherdates'), {duration:0.6})
				setTimeout(function(){infodestTabs('0')}, 900);
				setTimeout(function(){infodestTopTabsEnable();},1400);
			}
		}
	}

	if (tab == '2')
	{
		if ($('infodest_top_tabs').style.backgroundPosition != "0px -90px")
		{
			if ($('infodest_pix_hotel').style.display == "block")
			{
				infodestTopTabsDisable();
				new Effect.toggle($('infodest_pix_hotel'), 'Blind', {duration:0.6})
				setTimeout(function(){
					$('infodest_pix_hotel').style.display = "none";
					$('infodest_top_tabs').style.backgroundPosition = "0px -90px";
					new Effect.toggle($('infodest_satellite'), 'Blind', {duration:0.6})
				}, 900);
				setTimeout(function(){
					$('infodest_satellite_content').style.display = "block";
					satelliteInitialize(lat, long, zoom);
					$('infodest_satellite').style.display = "block";
				}, 1800);
				setTimeout(function(){infodestTopTabsEnable();},1900);
			}
			if ($('infodest_pix_region').style.display == "block")
			{
				infodestTopTabsDisable();
				new Effect.toggle($('infodest_pix_region'), 'Blind', {duration:0.6})
				setTimeout(function(){
					$('infodest_pix_region').style.display = "none";
					$('infodest_top_tabs').style.backgroundPosition = "0px -90px";
					new Effect.toggle($('infodest_satellite'), 'Blind', {duration:0.6})
				}, 900);
				setTimeout(function(){
					$('infodest_satellite_content').style.display = "block";
					satelliteInitialize(lat, long, zoom);
					$('infodest_satellite').style.display = "block";
				}, 1800);
				setTimeout(function(){infodestTopTabsEnable();},1900);
			}
		}
	}
}

function infodestTopTabsDisable() {
	$('infodest_top_tabs_disable').style.width = "550px";
	$('infodest_top_tabs_disable').style.height = "45px";
}

function infodestTopTabsEnable() {
	$('infodest_top_tabs_disable').style.width = "0px";
	$('infodest_top_tabs_disable').style.height = "0px";
}

function satelliteInitialize(lat, long, zoom) {
	var map = new google.maps.Map2(document.getElementById("infodest_satellite_google"));
	map.setCenter(new google.maps.LatLng(lat, long), zoom);
	map.addControl(new GSmallZoomControl3D());
	map.addControl(new GMapTypeControl());
	map.setMapType(G_SATELLITE_MAP);
}


function infodestTabs(tab) {

	//ANALYTICS
	var info_google_title;
	
	if(tab ==0)	{ info_google_title = "Summary"};
	if(tab ==1)	{ info_google_title = "Climate"};
	if(tab ==2)	{ info_google_title = "Attractions"};
	if(tab ==3)	{ info_google_title = "Sell off"};
	
	pageTracker._trackEvent('Onglet Info Destination', 'Click', info_google_title);
	
	if ($('infodest'))
	{
		infodestTabsDisable();
		var tabsArray = ["infodest_summary", "infodest_climate", "infodest_attractions", "infodest_lastminute"];
		for (i = 0; i <4; i++)
		{
			if ($(tabsArray[i]).style.display == "block")
			{
				new Effect.toggle($(tabsArray[i]), 'Blind', {duration:0.4});
			}
		}
		setTimeout(
			function(){
				switch (tab)
				{
					case '0':
						$('infodest_content_tabs').style.backgroundPosition = "0px 0px";
						break;
					case '1': 
						$('infodest_content_tabs').style.backgroundPosition = "0px -45px";
						break;
					case '2':
						$('infodest_content_tabs').style.backgroundPosition = "0px -90px";
						break;
					case '3':
						$('infodest_content_tabs').style.backgroundPosition = "0px -135px";
						break;
				}
				
	
				new Effect.toggle($(tabsArray[tab]), 'Blind', {duration:0.4})
				setTimeout(function(){
					$(tabsArray[tab]).style.display = "block";
				}, 450);
			}
		, 450);
		setTimeout(function(){infodestTabsEnable();},100);
	}
	else if ($('infodest_fiche'))
	{
		infodestTabsDisable();
		var frametimer = '0';
		if (tab != '0')
		{
		resizeParentFrame('441');
		frametimer = '1000';
		}
		setTimeout(function(){	
			var tabsArray = ["infodest_summary", "infodest_climate", "infodest_attractions", "infodest_lastminute"];
			//for (var i in tabsArray.length()) {
			for (i = 0; i <4; i++)
			{
				//alert($(tabsArray[i]));
				if ($(tabsArray[i]).style.display == "block")
				{
					$(tabsArray[i]).style.display = "none";;
				}
			}
	
			switch (tab)
			{
				case '0':
					$('infodest_content_tabs').style.backgroundPosition = "0px 0px";
					break;
				case '1': 
					$('infodest_content_tabs').style.backgroundPosition = "0px -45px";
					break;
				case '2':
					$('infodest_content_tabs').style.backgroundPosition = "0px -90px";
					break;
				case '3':
					$('infodest_content_tabs').style.backgroundPosition = "0px -135px";
					break;
			}
				
			$(tabsArray[tab]).style.display = "block";
			resizeParentFrame();
		}, frametimer);
		setTimeout(function(){infodestTabsEnable();},1000 + parseInt(frametimer));

	}
}

function infodestTabsDisable() {
	$('infodest_content_tabs_disable').style.width = "550px";
	$('infodest_content_tabs_disable').style.height = "45px";
}

function infodestTabsEnable() {
	$('infodest_content_tabs_disable').style.width = "0px";
	$('infodest_content_tabs_disable').style.height = "0px";
}


function resizeParentFrame(h) {
	if (h)
	{
		window.parent.packagesDetailsFramesize(h);
	}
	else
	{
		var newheight = $('infodest_fiche').offsetHeight;
		window.parent.packagesDetailsFramesize(newheight);
	}
}

function infodestAttractionsPix(title, pixurl)
{
	if ($('infodest'))
	{
		Lightview.show({ href: pixurl, rel: 'flash', title: title, options: {topclose: true, autosize: true} });
	}
	else if ($('infodest_fiche'))
	{
		window.parent.Lightview.show({ href: pixurl, rel: 'flash', title: title, options: {topclose: true, autosize: true} });
	}
}

function infodestYoutube(youtubeurl)
{
	if ($('infodest'))
	{
		Lightview.show({ href: youtubeurl, rel: 'flash', title: '', options: {topclose: true, autosize: true} });
	}
	else if ($('infodest_fiche'))
	{
		window.parent.Lightview.show({ href: youtubeurl, rel: 'flash', title: '', options: {topclose: true, autosize: true} });
	}
}

//Init the carousel on page load
Event.observe(window, "load", function() {
    if ($("infodest_pix_carousel_hotel")) {
        var thumb_carousel = new Carousel('infodest_pix_carousel_hotel',
            $$('#infodest_pix_thumbnails_hotel .infodest_pix_thumb_page'),
            $$('#infodest_pix_paging_hotel .carousel-control'), {
                afterMove : function(){
                    var carousel_index = thumb_carousel.current._index;
                    $("carousel_current_page").update(carousel_index+1);
					
					//ANALYTICS
					pageTracker._trackEvent('Carousel', 'Change page', 'Hotel pictures');
                }
        });
    }  
});

Event.observe(window, "load", function() {
    if ($("infodest_pix_carousel_region")) {
        var thumb_carousel = new Carousel('infodest_pix_carousel_region',
            $$('#infodest_pix_thumbnails_region .infodest_pix_thumb_page'),
            $$('#infodest_pix_paging_region .carousel-control'), {
                afterMove : function(){
                    var carousel_index = thumb_carousel.current._index;
                    $("carousel_current_page").update(carousel_index+1);
					
					//ANALYTICS
					pageTracker._trackEvent('Carousel', 'Change page', 'Region pictures');
                }
        });
    } 
});


