//MTCA-WW-001-16
//2/23/2012 12:44:01 AM

//MTCA-STG-001-01
//6/13/2011 12:28:35 AM

<!--PAGENAME:/fr/main.js--><!--CONTENT_ID:129062-->
var $j = jQuery.noConflict();

var cALIAS = "SEA";
var hovering_popup = false;
var popup_time_over = false;
var popup_closed = false;
var playing = true;
var secondaryPlaying = true;

$j(document).ready(function () {
	$j("div#tc_globalnav > ul li a").each(function(){
		if ($j(this).text().indexOf(" and ") >= 0) {
			$j(this).text($j(this).text().replace(" and ", " & "));
		}
	});

    $j("a.myPlayer").flowplayer({
        src: "http://builds.flowplayer.netdna-cdn.com/27399/425/flowplayer-3.2.0-0.swf",
        //wmode: 'opaque'
        wmode: 'transparent'
    });

    // ---------------------- MASTER SLIDESHOW -----------------------------
    $j("#master_slideshow_nav ul").tabs("#master_slideshow > div", {
        effect: 'fade',
        onBeforeClick: function () {
            if ($f()) {
                $f().unload();
            }
        }
    });

    $j("#master_slideshow_nav #watch_video").click(function () {
        playPause("pause");
        $j('#master_slideshow_nav #watch_video').removeClass('show').addClass('hide');
        $j('#master_slideshow_nav #view_images').removeClass('hide').addClass('show');
    });

    $j("#master_slideshow_nav #view_images").click(function () {
        $j('#master_slideshow_nav #view_images').removeClass('show').addClass('hide');
        $j('#master_slideshow_nav #watch_video').removeClass('hide').addClass('show');
    });

    $j('#master_slideshow_nav #view_images').removeClass('show').addClass('hide');

    // ---------------------- IMAGE SLIDESHOW -----------------------------
    $j("#slideshow_nav ul").tabs("#image_panes > div", {

        effect: 'fade',
        fadeInSpeed: 400,
        fadeOutSpeed: 200,

        // start from the beginning after the last tab
        rotate: true,

        // STOPS THE VIDEO WHEN SLIDE CLICKED
        onBeforeClick: function () {
            if ($f()) {
                $f().unload();
            }
        }
    }).slideshow({ autoplay: true, interval: 4000, clickable: false });



    // PAUSE AND PLAY BUTTON ON SLIDESHOW
    $j('#playPausebtn').click(function (event) {
        if (playing) {
            playPause("pause");
        }
        else {
            playPause("play");
        }
	event.preventDefault();
    });

    $j('#image_panes div a').click(function (event) {
        playPause("pause");
	//event.preventDefault();
    });



    // PAUSES THE SLIDESHOW ON SLIDE NAV CLICK
    $j("#slideshow_nav ul li a").click(function (event) {
        playPause("pause");
	event.preventDefault();
    });


    // -------------  VIDEO SLIDESHOW ----------------

    // VIDEO SLIDESHOW
    $j("#video_slideshow_nav ul").tabs("#video_panes > div", {

        effect: 'fade',
        fadeInSpeed: 400,
        fadeOutSpeed: 200,

        // start from the beginning after the last tab
        rotate: true,

        // STOPS THE VIDEO WHEN SLIDE CLICKED
        onBeforeClick: function () {
            $f().unload();
        }
    })



    $j("#video_slideshow_nav #view_images").click(function () {
        playPause("pause");
    });


    // DROPDOWN FOR NAV
    $j(".dropdown dt a").click(function () {
        $j(".dropdown dd ul").toggle();
    });

    $j(".dropdown dd ul li a").click(function () {
        var text = $j(this).html();
        $j(".dropdown dt a span").html(text);
        $j(".dropdown dd ul").hide();
    });

    function getSelectedValue(id) {
        return $j("#" + id).find("dt a span.value").html();
    }

    $j(document).bind('click', function (e) {
        var $jclicked = $j(e.target);
        if (!$jclicked.parents().hasClass("dropdown"))
            $j(".dropdown dd ul").hide();
    });


    /* POPUP FUNCTIONALITY */
    $j("#gateway_dep_top").bind({
        change: function () {
            //alert("in");
            hovering_popup = true;
            hide_popup();
            popup_closed = true;
        }
    });

    $j("#popup").bind({
        mouseenter: function () {
            hovering_popup = true;
        },
        mouseleave: function () {
            hovering_popup = false;

            setTimeout(function () {
                if (popup_time_over && !popup_closed && !hovering_popup) {
                    hide_popup();
                    popup_closed = true;
                }
            }
		, 100);
        }
    });


    // SLIDE NAV TOOLTIP CAPTIONS
    // SLIDE NAV TOOLTIP CAPTIONS
    $j("#slide1").tooltip({
        // use div.tooltip as our tooltip
        tip: '#tooltip1'
    });

    $j("#slide2").tooltip({
        // use div.tooltip as our tooltip
        tip: '#tooltip2'
    });

    $j("#slide3").tooltip({
        // use div.tooltip as our tooltip
        tip: '#tooltip3'
    });

    $j("#slide4").tooltip({
        // use div.tooltip as our tooltip
        tip: '#tooltip4'
    });

    $j("#slide5").tooltip({
        // use div.tooltip as our tooltip
        tip: '#tooltip5'
    });
    $j("#slide6").tooltip({
        // use div.tooltip as our tooltip
        tip: '#tooltip6'
    });

    $j("#slide7").tooltip({
        // use div.tooltip as our tooltip
        tip: '#tooltip7'
    });

    $j("#slide8").tooltip({
        // use div.tooltip as our tooltip
        tip: '#tooltip8'
    });

    $j("#slide9").tooltip({
        // use div.tooltip as our tooltip
        tip: '#tooltip9'
    });

    $j("#slide10").tooltip({
        // use div.tooltip as our tooltip
        tip: '#tooltip10'
    });


    function playPause(request) {
        if (request == "pause") {
            $j("#slideshow_nav ul").data("slideshow").stop();
            $j('#playPausebtn').removeClass('pause').addClass('play')
            playing = false;
        }
        else if (request == "play") {
            $j("#slideshow_nav ul").data("slideshow").play();
            $j('#playPausebtn').removeClass('play').addClass('pause')
            playing = true;
        }
    }
	
	function secondaryPlayPause(request) {
		if (request == "pause") {
			$j("#secondary_slideshow_nav ul").data("slideshow").stop();
			$j('#secondary_playPausebtn').removeClass('pause').addClass('play')
			secondaryPlaying = false;
		}
		else if (request == "play" ) {
			$j("#secondary_slideshow_nav ul").data("slideshow").play();		
			$j('#secondary_playPausebtn').removeClass('play').addClass('pause')
			secondaryPlaying = true;
		}
	}
	
	
	// ---------------------- SECONDARY SLIDESHOW -----------------------------
	
	$j("#secondary_slideshow_nav #watch_video").click(function() {
		secondaryPlayPause("pause");
		$j('#secondary_slideshow_nav #watch_video').removeClass('show').addClass('hide');
		$j('#secondary_slideshow_nav #view_images').removeClass('hide').addClass('show');
	});
	
	$j("#secondary_slideshow_nav #view_images").click(function() {
		$j('#secondary_slideshow_nav #view_images').removeClass('show').addClass('hide');
		$j('#secondary_slideshow_nav #watch_video').removeClass('hide').addClass('show');
	});
	
	$j('#secondary_slideshow_nav #view_images').removeClass('show').addClass('hide');
	
// ---------------------- IMAGE SLIDESHOW -----------------------------
	$j("#secondary_slideshow_nav ul").tabs("#secondary_image_panes > div", {

		effect: 'fade', 
		fadeInSpeed: 400,
		fadeOutSpeed: 200,
		
		// start from the beginning after the last tab
		rotate: true,
		
		// STOPS THE VIDEO WHEN SLIDE CLICKED
		onBeforeClick: function() {
			if ($f()) {
				$f().unload();		
			}
		} 
	}).slideshow({autoplay: true, interval: 4000, clickable:false}); 
	
	

	// PAUSE AND PLAY BUTTON ON SLIDESHOW
	$j('#secondary_playPausebtn').click(function(event) {
		if (secondaryPlaying) {
			secondaryPlayPause("pause");
		}
		else {
			secondaryPlayPause("play");
		}
		event.preventDefault();
	});
	
	$j('#secondary_image_panes div a').click(function(event) {
		secondaryPlayPause("pause");
		//event.preventDefault();
	});

	

	// PAUSES THE SLIDESHOW ON SLIDE NAV CLICK
	$j("#secondary_slideshow_nav ul li a").click(function(event) {
		secondaryPlayPause("pause");
		event.preventDefault();	
	});
	
	// SLIDE NAV TOOLTIP CAPTIONS
	$j("#secondary_slide1").tooltip({ 
		   // use div.tooltip as our tooltip
		   tip: '#secondary_tooltip1'
	});
	
	$j("#secondary_slide2").tooltip({ 
		   // use div.tooltip as our tooltip
		   tip: '#secondary_tooltip2'
	});
	
	$j("#secondary_slide3").tooltip({ 
		   // use div.tooltip as our tooltip
		   tip: '#secondary_tooltip3'
	});
	
	$j("#secondary_slide4").tooltip({ 
		   // use div.tooltip as our tooltip
		   tip: '#secondary_tooltip4'
	});
	
	$j("#secondary_slide5").tooltip({ 
		   // use div.tooltip as our tooltip
		   tip: '#secondary_tooltip5'
	});
	$j("#secondary_slide6").tooltip({ 
		   // use div.tooltip as our tooltip
		   tip: '#secondary_tooltip6'
	});
	
	$j("#secondary_slide7").tooltip({ 
		   // use div.tooltip as our tooltip
		   tip: '#secondary_tooltip7'
	});
	
	$j("#secondary_slide8").tooltip({ 
		   // use div.tooltip as our tooltip
		   tip: '#secondary_tooltip8'
	});
	
	$j("#secondary_slide9").tooltip({ 
		   // use div.tooltip as our tooltip
		   tip: '#secondary_tooltip9'
	});
	
	$j("#secondary_slide10").tooltip({ 
		   // use div.tooltip as our tooltip
		   tip: '#secondary_tooltip10'
	});


    //run the popup effect
    //setTimeout(function(){$j("#popup").show("slide", { direction:"down", times:3 },1000, run_time_check_hover ) }, 1000);

    $j("#change_gateway").click(function () {
        popup_closed = false;
        $j("#popup").show("slide", { direction: "down", times: 3 }, 1000, run_time_check_hover)
    });

    //callback function to bring a hidden box back
    function run_time_check_hover() {
        setTimeout(function () {
            if (!hovering_popup && !popup_closed) {
                hide_popup();
                popup_closed = true;
            }
            popup_time_over = true;
        }
		, 8000);
    };


    function hide_popup() {
        $j("#popup").hide("slide", { direction: "down", times: 3 }, 1000);
        popup_closed = true;
        $j("#popup_opener").show("slide", { direction: "down", times: 3 });
    }


    $j('#popup_opener').click(function (event) {
        //setTimeout(function(){
        //$j("#popup").show("slide", { direction:"down", times:3 },1000, run_time_check_hover ) }, 1000);	
        hovering_popup = false;
        popup_time_over = false;
        popup_closed = false;
        event.stopImmediatePropagation();

        $j(this).hide("slide", { direction: "down", times: 3 });
        setTimeout(function () { $j("#popup").show("slide", { direction: "down", times: 3 }, 1000, run_time_check_hover) }, 1000);

        //alert("clicked");
        return false;
        //$j("#popup").show("slide", { direction:"down", times:3 },1000, run_time_check_hover);	
        //run_time_check_hover();
        //$j("#popup").show("slide", { direction:"down", times:3 },1000);
        //$j("#popup").show("slide", { direction:"down", times:3 },1000, run_time_check_hover );
        //setTimeout(function(){
        //	$j("#popup").show("slide", { direction:"down", times:3 },1000, run_time_check_hover ) }, 1000);		
    });

    $j('#popup_close').click(function (event) {
        hide_popup();
    });


    $j("div#tc_globalnav > ul li:last a").css("border", "none");
    $j("div#tc_globalnav a.tc_globalnav_parent").click(function (event) {
        //hide current flyouts if required
        $j("div#tc_globalnav div.tc_globalnav_flyout").slideUp("fast").delay(200);
        if ($j(this).parent().hasClass("tc_selected")) {
            $j(this).parent().removeClass("tc_selected");
        } else {
            $j("div#tc_globalnav > ul li").removeClass("tc_selected");
            $j("div#tc_globalnav div.tc_globalnav_flyout[id='" + $j(this).attr("href").substring(1) + "']").slideDown("fast");
            $j(this).parent().addClass("tc_selected");
        }
        event.preventDefault();
        return false;
    });
    $j("div.tc_globalnav_flyout a.tc_close").click(function (event) {
        $j(this).parent().slideUp("fast");
        $j("div#tc_globalnav > ul li").removeClass("tc_selected");
        event.preventDefault();
    });
    $j("div#tc_header_location a").click(function (event) {
        if ($j("div#tc_header_location div#tc_header_location_form").hasClass("tc_active")) {
            $j("div#tc_header_location div#tc_header_location_form").slideUp("fast");
            $j("div#tc_header_location div#tc_header_location_form").removeClass("tc_active");
            $j(this).removeClass("tc_active");
        } else {
            $j(this).addClass("tc_active");
            $j("div#tc_header_location div#tc_header_location_form").slideDown("fast");
            $j("div#tc_header_location div#tc_header_location_form").addClass("tc_active");
        }
        event.preventDefault();
    });
    $j("li#tc_header_emaillink a.tc_header_emaillink").click(function (event) {
        if ($j("div#tc_header_links div.tc_email_signup").hasClass("tc_active")) {
            $j("div#tc_header_links div.tc_email_signup").slideUp("fast");
            $j("div#tc_header_links div.tc_email_signup").removeClass("tc_active");
            $j(this).removeClass("tc_active");
        } else {
            $j(this).addClass("tc_active");
            $j("div#tc_header_links div.tc_email_signup").slideDown("fast");
            $j("div#tc_header_links div.tc_email_signup").addClass("tc_active");
        }
        event.preventDefault();
    });
    $j("li#tc_header_emaillink2 a.tc_header_emaillink2").click(function (event) {
        if ($j("div#tc_header_links2 div.tc_email_signup2").hasClass("tc_active")) {
            $j("div#tc_header_links2 div.tc_email_signup2").slideUp("fast");
            $j("div#tc_header_links2 div.tc_email_signup2").removeClass("tc_active");
            $j(this).removeClass("tc_active");
        } else {
            $j(this).addClass("tc_active");
            $j("div#tc_header_links2 div.tc_email_signup2").slideDown("fast");
            $j("div#tc_header_links2 div.tc_email_signup2").addClass("tc_active");
        }
        event.preventDefault();
    });
    updateBookingEngineHeader();
    $j("div#booking_category input[type='radio']").click(function () {
        updateBookingEngineHeader();
    });
    $j("span.tc_price").hover(
		function () {
		    $j(this).css("background-position", "0px -80px");
		},
		function () {
		    $j(this).css("background-position", "0px 0px");
		}
	);
	$j("ul.tc_generic_tabs").tabs("div.tc_generic_tab_panes > div", {
		effect: "fade",
		onClick: function(event, index){
			$j("ul.tc_generic_tabs li").removeClass("tc_selected");
			$j("ul.tc_generic_tabs li").eq(index).addClass("tc_selected");
		}
	});
	$j("table.tc_content_grid").each(function(){
		$j("tr:even", this).addClass("tc_even");
	});
	
    $j(document).click(function () {
        //$j("div#tc_globalnav div.tc_globalnav_flyout").slideUp("fast").delay(400);
        //$j("div#tc_globalnav > ul li").removeClass("tc_selected");
    });
	if (default_gateway_dep && nearestGateway) {
		var selectedGWCity = $j('#gateway_dep_top').find('option:contains(' + default_gateway_dep + ')').text();
		if (selectedGWCity) selectedGWCity = selectedGWCity.substring(0, selectedGWCity.indexOf("(") - 1);
		$j("span.tc_header_location_current").html(selectedGWCity + " " + default_gateway_dep);
		$j("#tc_header_location_form p strong").html(nearestGateway);
		$j("#gateway_dep_top option:contains(" + default_gateway_dep + ")").attr("selected", true);
	}
	$j("div.tc_deals_listing_item a.tc_map_link").click(function(event){
		$j(this).parent().find("div.tc_item_gmap_static").slideDown("fast");
		$j(this).hide();
		event.preventDefault();
	});
	$j("div.tc_item_gmap_static a").click(function(event){
		$j(this).parent().slideUp("fast").parent().find("a.tc_map_link").show();
		event.preventDefault();
	});
	$j("select#gwcode option[value='" + default_gateway_dep +"']").attr("selected","selected");
	if ($j("div#tc_deals_listing").length > 0) {
		updateResultsListSummary();
	}
	$j("div.tc_foreign_exchange a").click(function(event){
		event.preventDefault();
	});
	if ($j(window).width() > 500){
		$j("a[href^='tel:']").click(function(event){
			event.preventDefault();
		});
	}
});







/* DEALS TABS */
$j(function () {
    var tabContainers = $j('div.tabs > div');
    tabContainers.hide().filter(':first').show();

    $j('div.tabs ul.tabNavigation a').click(function () {
        tabContainers.hide();
        tabContainers.filter(this.hash).show();
        $j('div.tabs ul.tabNavigation a').removeClass('selected');
        $j(this).addClass('selected');
        return false;
    }).filter(':first').click();
});


function paginate(ind, slide) {
    ind = ind + 1;
    if (ind == 1) return '<li><a href="#" class="pagination' + ind + '" name="tooltip' + ind + '"></a></li>';
    else return '<li><a href="#" class="pagination' + ind + '" name="tooltip' + ind + '"></a></li>';
}


function updateBookingEngineHeader() {
    $j("div#tc_booking_engine h3 span").html($j("div#booking_category input:checked").parent().text());
}

function initializeGMap(whichElement) {
    var latlng = new google.maps.LatLng(-34.397, 150.644);
    var myOptions = {
        zoom: 8,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById(whichElement), myOptions);
}

function updateHorizScrollerPagination(position, parent) {
    $j("#" + parent + " div.tc_horizontal_scroller_pagination li").each(function () {
        $j(this).find("img").attr("src", function () {
            return this.src.replace("_on", "_off");
        });
    });
    $j("#" + parent + " div.tc_horizontal_scroller_pagination li").eq(position / 3).find("img").attr("src", function () {
        return this.src.replace("_off", "_on")
    });
    if (position / 3 == 0) {
        $j("#" + parent + " div.tc_horizontal_scroller_nav a.tc_prev").css("background-position", "0px 0px");
    } else {
        $j("#" + parent + " div.tc_horizontal_scroller_nav a.tc_prev").css("background-position", "-22px 0px");
    }
    if ($j("#" + parent + " div#tc_horizontal_scroller_list ul li").length > 3) {
        if (position / 3 < $j("#" + parent + " div.tc_horizontal_scroller_pagination li").length - 1) {
            $j("#" + parent + " div.tc_horizontal_scroller_nav a.tc_next").css("background-position", "-22px 0px");
        } else {
            $j("#" + parent + " div.tc_horizontal_scroller_nav a.tc_next").css("background-position", "0px 0px");
        }
    }
}

function updateVerticalScrollerNavigation(position, parent, windowSize) {
	if (position == 0) {
		//at the top
		$j("#" + parent + " div.tc_vertical_scroller_nav a.tc_prev").css("background-position", "50% 0px");
		if ($j("#" + parent + " div.tc_vertical_scroller_list ul li").length > windowSize) {
			$j("#" + parent + " div.tc_vertical_scroller_nav a.tc_next").css("background-position", "50% -22px");
		}
	} else {
		if ($j("#" + parent + " div.tc_vertical_scroller_list ul li").length > windowSize) {
			$j("#" + parent + " div.tc_vertical_scroller_nav a.tc_prev").css("background-position", "50% -22px");
			if (($j("#" + parent + " div.tc_vertical_scroller_list ul li").length - 1) - position < windowSize) {
				$j("#" + parent + " div.tc_vertical_scroller_nav a.tc_next").css("background-position", "50% 0px");
			}
		}
	}
}


function initializeBrowseTopDealsScroller(whichType) {
	//show the first detail item for vacations
	$j("#tc_browse_top_deals_vacations div.tc_vertical_scroller_details div.tc_browse_top_deals_item").eq(0).show();
	//show the first detail item for cruises (cruises hidden at start)
	$j("#tc_browse_top_deals_cruises div.tc_vertical_scroller_details div.tc_browse_top_deals_item").eq(0).show();
	//iterate through available detail items (vacations & cruises) to create scroller ul structure
	$j("#tc_browse_top_deals_vacations div.tc_vertical_scroller_details div.tc_browse_top_deals_item").each(function(){
		$j("#tc_browse_top_deals_vacations div.tc_vertical_scroller_list ul").append("<li><span class=\"tc_location\">" + $j(this).find("div.tc_left span.tc_location").html() + "</span><span class=\"tc_name\">" + $j(this).find("div.tc_left a.tc_location_link").html() + "</span><span class=\"tc_price\">" + $j(this).find("div.tc_right span.tc_price span").html() + "</span></li>");
	});
	$j("#tc_browse_top_deals_cruises div.tc_vertical_scroller_details div.tc_browse_top_deals_item").each(function(){
		$j("#tc_browse_top_deals_cruises div.tc_vertical_scroller_list ul").append("<li><span class=\"tc_location\">" + $j(this).find("div.tc_left span.tc_location").html() + "</span><span class=\"tc_name\">" + $j(this).find("div.tc_left a.tc_location_link").html() + "</span><span class=\"tc_price\">" + $j(this).find("div.tc_right span.tc_price span").html() + "</span></li>");
	});
	
	updateVerticalScrollerNavigation(0,"tc_browse_top_deals_vacations_scroller",4);
	updateVerticalScrollerNavigation(0,"tc_browse_top_deals_flights_scroller",3);
	updateVerticalScrollerNavigation(0,"tc_browse_top_deals_cruises_scroller",4);
	
	//vacations
	$j("#tc_browse_top_deals_vacations div.tc_vertical_scroller_list ul li:first").addClass("tc_selected");
	$j("#tc_browse_top_deals_vacations div.tc_vertical_scroller_list ul li:first").css("border-top", "1px solid #bfe4f6");
	$j("#tc_browse_top_deals_vacations div.tc_vertical_scroller_list ul li").click(function(){
		$j("#tc_browse_top_deals_vacations div.tc_vertical_scroller_list ul li").removeClass("tc_selected");
		$j(this).addClass("tc_selected");
		showTopDealDetailContent($j("#tc_browse_top_deals_vacations div.tc_vertical_scroller_list ul li").index($j(this)));
	});
	//cruises
	$j("#tc_browse_top_deals_cruises div.tc_vertical_scroller_list ul li:first").addClass("tc_selected");
	$j("#tc_browse_top_deals_cruises div.tc_vertical_scroller_list ul li:first").css("border-top", "1px solid #bfe4f6");
	$j("#tc_browse_top_deals_cruises div.tc_vertical_scroller_list ul li").click(function(){
		$j("#tc_browse_top_deals_cruises div.tc_vertical_scroller_list ul li").removeClass("tc_selected");
		$j(this).addClass("tc_selected");
		showTopDealDetailContent($j("#tc_browse_top_deals_cruises div.tc_vertical_scroller_list ul li").index($j(this)));
	});
	$j("#tc_browse_top_deals_" + whichType.toLowerCase()).show();
	
	$j("#tc_browse_top_deals_flights_scroller_list").serialScroll({
		items:"li",
		event:"click.serialScroll",
		prev:"#tc_browse_top_deals_flights a.tc_prev",
		next:"#tc_browse_top_deals_flights a.tc_next",
		duration:500,
		axis: "y",
		force:true,
		cycle:false,
		step:3,
		onBefore:function(e, elem, $pane, $items, pos){
			updateVerticalScrollerNavigation(pos, $j($pane).parent().attr("id"), 3);
		},
		onAfter:function(elem){
			//
		}
	});
	
	$j("#tc_browse_top_deals_vacations_scroller_list").serialScroll({
		items:"li",
		event:"click.serialScroll",
		prev:"#tc_browse_top_deals_vacations_scroller div.tc_vertical_scroller_nav a.tc_prev",
		next:"#tc_browse_top_deals_vacations_scroller div.tc_vertical_scroller_nav a.tc_next",
		duration:500,
		axis: "y",
		force:true,
		cycle:false,
		step:4,
		onBefore:function(e, elem, $pane, $items, pos){
			updateVerticalScrollerNavigation(pos, $j($pane).parent().attr("id"), 4);
		},
		onAfter:function(elem){
			//
		}
	});
	
	$j("#tc_browse_top_deals_cruises_scroller_list").serialScroll({
		items:"li",
		event:"click.serialScroll",
		prev:"#tc_browse_top_deals_cruises_scroller div.tc_vertical_scroller_nav a.tc_prev",
		next:"#tc_browse_top_deals_cruises_scroller div.tc_vertical_scroller_nav a.tc_next",
		duration:500,
		axis: "y",
		force:true,
		cycle:false,
		step:4,
		onBefore:function(e, elem, $pane, $items, pos){
			updateVerticalScrollerNavigation(pos, $j($pane).parent().attr("id"), 4);
		},
		onAfter:function(elem){
			//
		}
	});
}

function resetBrowseTopDealsScroller(whichType) {
	if (whichType == "VACATIONS") {
		//show the first detail item for vacations
		$j("#tc_browse_top_deals_vacations div.tc_vertical_scroller_details div.tc_browse_top_deals_item").eq(0).show();
		//iterate through available detail items (vacations & cruises) to create scroller ul structure
		$j("#tc_browse_top_deals_vacations div.tc_vertical_scroller_details div.tc_browse_top_deals_item").each(function(){
			$j("#tc_browse_top_deals_vacations div.tc_vertical_scroller_list ul").append("<li><span class=\"tc_location\">" + $j(this).find("div.tc_left span.tc_location").html() + "</span><span class=\"tc_name\">" + $j(this).find("div.tc_left a.tc_location_link").html() + "</span><span class=\"tc_price\">" + $j(this).find("div.tc_right span.tc_price span").html() + "</span></li>");
		});
		updateVerticalScrollerNavigation(0,"tc_browse_top_deals_vacations_scroller",4);
		//vacations
		$j("#tc_browse_top_deals_vacations div.tc_vertical_scroller_list ul li:first").addClass("tc_selected");
		$j("#tc_browse_top_deals_vacations div.tc_vertical_scroller_list ul li:first").css("border-top", "1px solid #bfe4f6");
		$j("#tc_browse_top_deals_vacations div.tc_vertical_scroller_list ul li").click(function(){
			$j("#tc_browse_top_deals_vacations div.tc_vertical_scroller_list ul li").removeClass("tc_selected");
			$j(this).addClass("tc_selected");
			showTopDealDetailContent($j("#tc_browse_top_deals_vacations div.tc_vertical_scroller_list ul li").index($j(this)));
		});
		$j("#tc_browse_top_deals_vacations_scroller_list").serialScroll({
			items:"li",
			event:"click.serialScroll",
			prev:"#tc_browse_top_deals_vacations_scroller div.tc_vertical_scroller_nav a.tc_prev",
			next:"#tc_browse_top_deals_vacations_scroller div.tc_vertical_scroller_nav a.tc_next",
			duration:500,
			axis: "y",
			force:true,
			cycle:false,
			step:4,
			onBefore:function(e, elem, $pane, $items, pos){
				updateVerticalScrollerNavigation(pos, $j($pane).parent().attr("id"), 4);
			},
			onAfter:function(elem){
				//
			}
		});
	} else if (whichType == "FLIGHTS") {
		updateVerticalScrollerNavigation(0,"tc_browse_top_deals_flights_scroller",3);
		$j("#tc_browse_top_deals_flights_scroller_list").serialScroll({
			items:"li",
			event:"click.serialScroll",
			prev:"#tc_browse_top_deals_flights a.tc_prev",
			next:"#tc_browse_top_deals_flights a.tc_next",
			duration:500,
			axis: "y",
			force:true,
			cycle:false,
			step:3,
			onBefore:function(e, elem, $pane, $items, pos){
				updateVerticalScrollerNavigation(pos, $j($pane).parent().attr("id"), 3);
			},
			onAfter:function(elem){
				//
			}
		});
	} else if (whichType == "CRUISES") {
		//show the first detail item for cruises (cruises hidden at start)
		$j("#tc_browse_top_deals_cruises div.tc_vertical_scroller_details div.tc_browse_top_deals_item").eq(0).show();
		//iterate through available detail items (vacations & cruises) to create scroller ul structure
		$j("#tc_browse_top_deals_cruises div.tc_vertical_scroller_details div.tc_browse_top_deals_item").each(function(){
			$j("#tc_browse_top_deals_cruises div.tc_vertical_scroller_list ul").append("<li><span class=\"tc_location\">" + $j(this).find("div.tc_left span.tc_location").html() + "</span><span class=\"tc_name\">" + $j(this).find("div.tc_left a.tc_location_link").html() + "</span><span class=\"tc_price\">" + $j(this).find("div.tc_right span.tc_price span").html() + "</span></li>");
		});
		updateVerticalScrollerNavigation(0,"tc_browse_top_deals_cruises_scroller",4);
		//cruises
		$j("#tc_browse_top_deals_cruises div.tc_vertical_scroller_list ul li:first").addClass("tc_selected");
		$j("#tc_browse_top_deals_cruises div.tc_vertical_scroller_list ul li:first").css("border-top", "1px solid #bfe4f6");
		$j("#tc_browse_top_deals_cruises div.tc_vertical_scroller_list ul li").click(function(){
			$j("#tc_browse_top_deals_cruises div.tc_vertical_scroller_list ul li").removeClass("tc_selected");
			$j(this).addClass("tc_selected");
			showTopDealDetailContent($j("#tc_browse_top_deals_cruises div.tc_vertical_scroller_list ul li").index($j(this)));
		});
		$j("#tc_browse_top_deals_cruises_scroller_list").serialScroll({
			items:"li",
			event:"click.serialScroll",
			prev:"#tc_browse_top_deals_cruises_scroller div.tc_vertical_scroller_nav a.tc_prev",
			next:"#tc_browse_top_deals_cruises_scroller div.tc_vertical_scroller_nav a.tc_next",
			duration:500,
			axis: "y",
			force:true,
			cycle:false,
			step:4,
			onBefore:function(e, elem, $pane, $items, pos){
				updateVerticalScrollerNavigation(pos, $j($pane).parent().attr("id"), 4);
			},
			onAfter:function(elem){
				//
			}
		});
	}
	$j("a.thickbox").unbind("click");
	tb_init("a.thickbox");
}

function showTopDealDetailContent(whichItem) {
    //hide the detail items, then show the new item
	$j("#tc_browse_top_deals_" + $j("div#tc_browse_top_deals input#activeTab").val().toLowerCase() + " div.tc_vertical_scroller_details div.tc_browse_top_deals_item").hide();
	$j("#tc_browse_top_deals_" + $j("div#tc_browse_top_deals input#activeTab").val().toLowerCase() + " div.tc_vertical_scroller_details div.tc_browse_top_deals_item").eq(whichItem).show();
}

function getCookie(c_name) {
	if (document.cookie.length>0) {
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1) {
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
}

function setDepartureCookie() {
    //called from header change location
	gatewayCookie = $j("select#gateway_dep_top option:selected").val();
	var myDate = new Date();
	myDate.setDate(myDate.getDate() + 30);
	SetCookie("default_gateway_dep", gatewayCookie, myDate);
	SetCookie("bpGWCode", gatewayCookie, myDate);
}

function listDeals(bptype) {
	//set the 'view all' link
	//set the current display tab
	$j("div#tc_browse_top_deals_vacations").hide();
	$j("div#tc_browse_top_deals_flights").hide();
	$j("div#tc_browse_top_deals_cruises").hide();
	$j("div#tc_browse_top_deals input#activeTab").val(bptype);
	$j("div#tc_browse_top_deals_header div.tc_tabbed_navigation ul li").removeClass("tc_selected");
	if (bptype == "VACATIONS") {
		$j("div#tc_browse_top_deals input#searchType").val("2362");
		$j("div#tc_browse_top_deals_header div.tc_tabbed_navigation ul li").eq(0).addClass("tc_selected");
		$j("div#tc_browse_top_deals_wrapper a#tc_browse_top_deals_alllink").html("Afficher toutes les aubaines vacances").attr("href","/fr/all-inclusive-vacation-packages.aspx");
	} else if (bptype == "FLIGHTS") {
		$j("div#tc_browse_top_deals input#searchType").val("108");
		$j("div#tc_browse_top_deals_header div.tc_tabbed_navigation ul li").eq(1).addClass("tc_selected");
		$j("div#tc_browse_top_deals_wrapper a#tc_browse_top_deals_alllink").html("Afficher toutes les aubaines sur les vols").attr("href","/fr/cheap-flights.aspx");
	} else if (bptype == "CRUISES") {
		$j("div#tc_browse_top_deals input#searchType").val("582");
		$j("div#tc_browse_top_deals_header div.tc_tabbed_navigation ul li").eq(2).addClass("tc_selected");
		$j("div#tc_browse_top_deals_wrapper a#tc_browse_top_deals_alllink").html("Afficher toutes les aubaines sur les croisi&#232;res").attr("href","/fr/cruise-vacations/best-cruise-deals.aspx");
	}
	$j("div#tc_browse_top_deals_" + bptype.toLowerCase()).show();
}

function listDestinationDeals(bptype) {
	//set the current display tab
	$j("div#tc_deals_listing div.tc_deals_listing_content").hide();
	$j("div#tc_destination_deals_header div.tc_tabbed_navigation ul li").removeClass("tc_selected");
	if (bptype == "VACATIONS") {
		$j("div#tc_destination_deals_header div.tc_tabbed_navigation ul li").eq(0).addClass("tc_selected");
		$j("select#sbcode2").hide();
		$j("select#sbcode").show();
	} else if (bptype == "FLIGHTS") {
		$j("div#tc_destination_deals_header div.tc_tabbed_navigation ul li").eq(1).addClass("tc_selected");
		$j("select#sbcode").hide();
		$j("select#sbcode2").show();
	}
	updateDestinationsResultsListSummary(bptype);
	$j("div#tc_deals_listing_" + bptype.toLowerCase() + "_content").show();
}

function processDeptCitySelect(whichElement) {
	//keep the user in the current tab context
	//query the current hidden field for the context, then make the ajax request & process
	//ajax request will bring back full HTML structure; insert in place & re-initialize after successful load
	$j("#tc_browse_top_deals_vacations_scroller").find("*").andSelf().unbind(".serialScroll");
	$j("#tc_browse_top_deals_flights_scroller").find("*").andSelf().unbind(".serialScroll");
	$j("#tc_browse_top_deals_cruises_scroller").find("*").andSelf().unbind(".serialScroll");
	$j("#tc_browse_top_deals_vacations_scroller_list ul").html("");
	$j("#tc_browse_top_deals_flights_scroller_list ul").html("");
	$j("#tc_browse_top_deals_cruises_scroller_list ul").html("");
	
	var SearchTypePA = "PA,LM,FO",SearchTypeFL = "RE,OW",SearchTypeCR = "CR";	
	
	if (document.getElementById("SearchType_Deals") != null)
	{
		SearchTypePA = document.getElementById("SearchType_Deals").value.replace(/'/g,"");
	}
	
	if (document.getElementById("SearchType_Deals_FL") != null)
	{
		SearchTypeFL = document.getElementById("SearchType_Deals_FL").value.replace(/'/g,"");
	}

	if (document.getElementById("SearchType_Deals_CR") != null)
	{
		SearchTypeCR = document.getElementById("SearchType_Deals_CR").value.replace(/'/g,"");
	}	
	
	
	var PriceRangePA = "",PriceRangeFL = "",PriceRangeCR = "";
	
	if (document.getElementById("PriceRange") != null)
	{
		PriceRangePA = document.getElementById("PriceRange").value.replace(/'/g,"");
	}
	
	if (document.getElementById("PriceRange_FL") != null)
	{
		PriceRangeFL = document.getElementById("PriceRange_FL").value.replace(/'/g,"");
	}

	if (document.getElementById("PriceRange_CR") != null)
	{
		PriceRangeCR = document.getElementById("PriceRange_CR").value.replace(/'/g,"");
	}	

	var DateRangePA = "",DateRangeFL = "",DateRangeCR = "";
	
	if (document.getElementById("DateRange") != null)
	{
		DateRangePA = document.getElementById("DateRange").value.replace(/'/g,"");
	}
	
	if (document.getElementById("DateRange_FL") != null)
	{
		DateRangeFL = document.getElementById("DateRange_FL").value.replace(/'/g,"");
	}

	if (document.getElementById("DateRange_CR") != null)
	{
		DateRangeCR = document.getElementById("DateRange_CR").value.replace(/'/g,"");
	}
	
	var DurationPA = "",DurationFL = "",DurationCR = "";
	
	if (document.getElementById("Duration") != null)
	{
		DurationPA = document.getElementById("Duration").value.replace(/'/g,"");
	}
	
	if (document.getElementById("Duration_FL") != null)
	{
		DurationFL = document.getElementById("Duration_FL").value.replace(/'/g,"");
	}

	if (document.getElementById("Duration_CR") != null)
	{
		DurationCR = document.getElementById("Duration_CR").value.replace(/'/g,"");
	}
	
	var TourOperatorPA = "", TourOperatorFL = "";

	if (document.getElementById("TourOperator") != null)
	{
		TourOperatorPA = document.getElementById("TourOperator").value.replace(/'/g,"");
	}
	
	if (document.getElementById("TourOperator_FL") != null)
	{
		TourOperatorFL = document.getElementById("TourOperator_FL").value.replace(/'/g,"");
	}

        var prov = "";
	if(document.getElementById("hidOPC") != null)
    {
        if (document.getElementById("hidOPC").value == "Y")
        {
            prov = "QC";
        }
    }
	
	//make ajax call for each pound code and place in each container
	$j.ajax({
		url: "http://" + HostName + "/Pages/Admin/WSRenderer.aspx?hotdealcode=%23%23%23%23PACKAGEBESTPICKS2_listformat%3dMINI|5%26maxPicks%3d20%26Language%3dFR%26Alias%3d" + cALIAS + "%26gwcode%3d" + $j(whichElement).find("option:selected").val() + "%26searchtype%3d" + SearchTypePA + "%26pkgPriceRange%3d" + PriceRangePA + "%26deptDateRange%3d" + DateRangePA + "%26pkgDuration%3d" + DurationPA + "%26pkgTourOperator%3d" + TourOperatorPA + "%26province%3d" + prov + "%26mytid%3d" + session + "%26sortby%3dPRICE%23%23%23%23",
		success: function(data){
			$j("div#tc_browse_top_deals_vacations").html($j(data).contents());
			resetBrowseTopDealsScroller("VACATIONS");
		},
		error: function(XMLHttpRequest, textStatus, errorThrown){
//			alert(errorThrown);
		},
		dataType: "html"
	});
	$j.ajax({
		url: "http://" + HostName + "/Pages/Admin/WSRenderer.aspx?hotdealcode=%23%23%23%23FLIGHTSBESTPICKS2_listformat%3dMINI|5%26maxPicks%3d20%26Language%3dFR%26Alias%3d" + cALIAS + "%26gwcode%3d" + $j(whichElement).find("option:selected").val() + "%26searchtype%3d" + SearchTypeFL + "%26pkgPriceRange%3d" + PriceRangeFL + "%26deptDateRange%3d" + DateRangeFL + "%26pkgDuration%3d" + DurationFL + "%26pkgTourOperator%3d" + TourOperatorFL + "%26province%3d" + prov + "%26mytid%3d" + session + "%26sortby%3dPRICE%23%23%23%23",
		success: function(data2){
			$j("div#tc_browse_top_deals_flights").html($j(data2).contents());
			resetBrowseTopDealsScroller("FLIGHTS");
		},
		error: function(XMLHttpRequest, textStatus, errorThrown){
//			alert(errorThrown);
		},
		dataType: "html"
	});
	$j.ajax({
		url: "http://" + HostName + "/Pages/Admin/WSRenderer.aspx?hotdealcode=%23%23%23%23CRUISESBESTPICKS2_listformat%3dMINI|5%26maxPicks%3d20%26Language%3dFR%26Alias%3d" + cALIAS + "%26gwcode%3d" + $j(whichElement).find("option:selected").val() + "%26searchtype%3d" + SearchTypeCR + "%26pkgPriceRange%3d" + PriceRangeCR + "%26deptDateRange%3d" + DateRangeCR + "%26pkgDuration%3d" + DurationCR + "%26province%3d" + prov + "%26mytid%3d" + session + "%26sortby%3dPRICE%23%23%23%23",
		success: function(data3){
			$j("div#tc_browse_top_deals_cruises").html($j(data3).contents());
			resetBrowseTopDealsScroller("CRUISES");
		},
		error: function(XMLHttpRequest, textStatus, errorThrown){
//			alert(errorThrown);
		},
		dataType: "html"
	});	
}

function processDeptCitySortBySelect_Listing(whichContext){

	var SearchTypePA = "PA,LM,FO",SearchTypeFL = "RE,OW",SearchTypeCR = "CR"

	if (document.getElementById("SearchType_Deals") != null)
	{
		SearchTypePA = document.getElementById("SearchType_Deals").value.replace(/'/g,"");
	}
	
	if (document.getElementById("SearchType_Deals_FL") != null)
	{
		SearchTypeFL = document.getElementById("SearchType_Deals_FL").value.replace(/'/g,"");
	}

	if (document.getElementById("SearchType_Deals_CR") != null)
	{
		SearchTypeCR = document.getElementById("SearchType_Deals_CR").value.replace(/'/g,"");
	}
			
			
	var PriceRangePA = "",PriceRangeFL = "",PriceRangeCR = "";
	
	if (document.getElementById("PriceRange") != null)
	{
		PriceRangePA = document.getElementById("PriceRange").value.replace(/'/g,"");
	}
	
	if (document.getElementById("PriceRange_FL") != null)
	{
		PriceRangeFL = document.getElementById("PriceRange_FL").value.replace(/'/g,"");
	}

	if (document.getElementById("PriceRange_CR") != null)
	{
		PriceRangeCR = document.getElementById("PriceRange_CR").value.replace(/'/g,"");
	}	
	
	
	var DateRangePA = "",DateRangeFL = "",DateRangeCR = "";
	
	if (document.getElementById("DateRange") != null)
	{
		DateRangePA = document.getElementById("DateRange").value.replace(/'/g,"");
	}
	
	if (document.getElementById("DateRange_FL") != null)
	{
		DateRangeFL = document.getElementById("DateRange_FL").value.replace(/'/g,"");
	}

	if (document.getElementById("DateRange_CR") != null)
	{
		DateRangeCR = document.getElementById("DateRange_CR").value.replace(/'/g,"");
	}
	

	var DurationPA = "",DurationFL = "",DurationCR = "";
	
	if (document.getElementById("Duration") != null)
	{
		DurationPA = document.getElementById("Duration").value.replace(/'/g,"");
	}
	
	if (document.getElementById("Duration_FL") != null)
	{
		DurationFL = document.getElementById("Duration_FL").value.replace(/'/g,"");
	}

	if (document.getElementById("Duration_CR") != null)
	{
		DurationCR = document.getElementById("Duration_CR").value.replace(/'/g,"");
	}
	
	
	var TourOperatorPA = "", TourOperatorFL = "";

	if (document.getElementById("TourOperator") != null)
	{
		TourOperatorPA = document.getElementById("TourOperator").value.replace(/'/g,"");
	}
	
	if (document.getElementById("TourOperator_FL") != null)
	{
		TourOperatorFL = document.getElementById("TourOperator_FL").value.replace(/'/g,"");
	}

    var prov = "";
	if(document.getElementById("hidOPC") != null)
    {
        if (document.getElementById("hidOPC").value == "Y")
        {
            prov = "QC";
        }
    }	
	
	//use whichContext to determine if we are in Vacations, Flights or Destinations context
	if (whichContext == "DESTINATIONS") {
		//for Destinations, there are two containers to populate with two separate service calls
		$j("div#tc_deals_listing_vacations_content").html("<div class=\"tc_loading\"></div>");
		$j("div#tc_deals_listing_flights_content").html("<div class=\"tc_loading\"></div>");
		var strURL = "";
		var strURL2 = "";
		var strDestCodes = $j("input#dcodes").val();
		if (strDestCodes != "") {
			//strDestCodes = strDestCodes.substring(0,strDestCodes.indexOf("<!"));
			strDestCodes = strDestCodes.replace(/&/g,"%26");
		} else {
			strDestCodes = "";
		}
		strURL = "http://" + HostName + "/Pages/Admin/WSRenderer.aspx?hotdealcode=%23%23%23%23PACKAGEBESTPICKS2_listformat%3dFULL|10%26maxPicks%3d10%26Language%3dFR%26Alias%3d" + cALIAS + "%26searchtype%3d" + SearchTypePA + "%26pkgPriceRange%3d" + PriceRangePA + "%26deptDateRange%3d" + DateRangePA + "%26pkgDuration%3d" + DurationPA + "%26pkgTourOperator%3d" + TourOperatorPA + "%26gwcode%3d" + $j("select#gwcode option:selected").val() + "%26sortby%3d" + $j("select#sbcode option:selected").val() + strDestCodes + "%26province%3d" + prov + "%26mytid%3d" + session + "%23%23%23%23";
		strURL2 = "http://" + HostName + "/Pages/Admin/WSRenderer.aspx?hotdealcode=%23%23%23%23FLIGHTSBESTPICKS2_listformat%3dFULL|10%26maxPicks%3d10%26Language%3dFR%26Alias%3d" + cALIAS + "%26searchtype%3d" + SearchTypeFL + "%26pkgPriceRange%3d" + PriceRangeFL + "%26deptDateRange%3d" + DateRangeFL + "%26pkgDuration%3d" + DurationFL + "%26pkgTourOperator%3d" + TourOperatorFL + "%26gwcode%3d" + $j("select#gwcode option:selected").val() + "%26sortby%3d" + $j("select#sbcode2 option:selected").val() + strDestCodes + "%26province%3d" + prov + "%26mytid%3d" + session +"%23%23%23%23";
		$j.ajax({
			url: strURL,
			success: function(data){
				//$j("div#tc_deals_listing_vacations_content").html($j(data));
				$j("div#tc_deals_listing_vacations_content").html(data);
				if ($j("div.tc_tabbed_navigation li.tc_selected a").text().indexOf("Vacation") >= 0) {
					updateDestinationsResultsListSummary("VACATIONS");
				}
				$j("a.thickbox").unbind("click");
				tb_init("a.thickbox");
				$j("div#tc_photosOverlayContainer").html("").hide();
				initializeListingMaps();
			},
			error: function(XMLHttpRequest, textStatus, errorThrown){
//				alert(errorThrown);
			},
			dataType: "html"
		});
		$j.ajax({
			url: strURL2,
			success: function(data2){
				//$j("div#tc_deals_listing_flights_content").html($j(data2));
				$j("div#tc_deals_listing_flights_content").html(data2);
				if ($j("div.tc_tabbed_navigation li.tc_selected a").text().indexOf("Flight") >= 0) {
					updateDestinationsResultsListSummary("FLIGHTS");
				}
				$j("a.thickbox").unbind("click");
				tb_init("a.thickbox");
				$j("div#tc_photosOverlayContainer").html("").hide();
				initializeListingMaps();
			},
			error: function(XMLHttpRequest, textStatus, errorThrown){
//				alert(errorThrown);
			},
			dataType: "html"
		});
	} else {
		$j("div.tc_deals_listing_content").html("<div class=\"tc_loading\"></div>");
		var strURL = "";
		var strDestCodes = "";
		if ($j("input#dcodes").length > 0) {
			strDestCodes = $j("input#dcodes").val();
		}
		if (whichContext == "VACATIONS") {
			strURL = "http://" + HostName + "/Pages/Admin/WSRenderer.aspx?hotdealcode=%23%23%23%23PACKAGEBESTPICKS2_listformat%3dFULL|10%26maxPicks%3d10%26Language%3dFR%26Alias%3d" + cALIAS + "%26searchtype%3d" + SearchTypePA + "%26pkgPriceRange%3d" + PriceRangePA + "%26deptDateRange%3d" + DateRangePA + "%26pkgDuration%3d" + DurationPA + "%26pkgTourOperator%3d" + TourOperatorPA + "%26gwcode%3d" + $j("select#gwcode option:selected").val() + "%26sortby%3d" + $j("select#sbcode option:selected").val() + "%26province%3d" + prov + "%26mytid%3d" + session +"%23%23%23%23";
		} else if (whichContext == "FLIGHTS") {
			if ($j("select#sbcode2").length > 0){
				strURL = "http://" + HostName + "/Pages/Admin/WSRenderer.aspx?hotdealcode=%23%23%23%23FLIGHTSBESTPICKS2_listformat%3dFULL|10%26maxPicks%3d10%26Language%3dFR%26Alias%3d" + cALIAS + "%26searchtype%3d" + SearchTypeFL + "%26pkgPriceRange%3d" + PriceRangeFL + "%26deptDateRange%3d" + DateRangeFL + "%26pkgDuration%3d" + DurationFL + "%26pkgTourOperator%3d" + TourOperatorFL + "%26gwcode%3d" + $j("select#gwcode option:selected").val() + "%26sortby%3d" + $j("select#sbcode2 option:selected").val() + strDestCodes + "%26province%3d" + prov + "%26mytid%3d" + session +"%23%23%23%23";
			} else {
				strURL = "http://" + HostName + "/Pages/Admin/WSRenderer.aspx?hotdealcode=%23%23%23%23FLIGHTSBESTPICKS2_listformat%3dFULL|10%26maxPicks%3d10%26Language%3dFR%26Alias%3d" + cALIAS + "%26searchtype%3d" + SearchTypeFL + "%26pkgPriceRange%3d" + PriceRangeFL + "%26deptDateRange%3d" + DateRangeFL + "%26pkgDuration%3d" + DurationFL + "%26pkgTourOperator%3d" + TourOperatorFL + "%26gwcode%3d" + $j("select#gwcode option:selected").val() + "%26sortby%3d" + $j("select#sbcode option:selected").val() + strDestCodes + "%26province%3d" + prov + "%26mytid%3d" + session +"%23%23%23%23";
			}
		} else if (whichContext == "CRUISES") {
			strURL = "http://" + HostName + "/Pages/Admin/WSRenderer.aspx?hotdealcode=%23%23%23%23CRUISESBESTPICKS2_listformat%3dFULL|10%26maxPicks%3d10%26Language%3dFR%26Alias%3d" + cALIAS + "%26searchtype%3d" + SearchTypeCR + "%26pkgPriceRange%3d" + PriceRangeCR + "%26deptDateRange%3d" + DateRangeCR + "%26pkgDuration%3d" + DurationCR + "%26gwcode%3d" + $j("select#gwcode option:selected").val() + "%26sortby%3d" + $j("select#sbcode option:selected").val() + "%26province%3d" + prov + "%26mytid%3d" + session +"%23%23%23%23";
		}
		$j.ajax({
			url: strURL,
			success: function(data){
				$j("div.tc_deals_listing_content").html(data);
				$j("a.thickbox").unbind("click");
				tb_init("a.thickbox");
				$j("div#tc_photosOverlayContainer").html("").hide();
				initializeListingMaps();
				updateResultsListSummary();
			},
			error: function(XMLHttpRequest, textStatus, errorThrown){
//				alert(errorThrown);
			},
			dataType: "html"
		});
	}
}

function getAllForeignExchangeRates(){
	if ($j("div#tc_foreign_exchange_all").html() == "") {
		$j.ajax({
			url: "http://" + HostName + "/Pages/Admin/WSRenderer.aspx?wsRequest=https%3a%2f%2fwebservices-ext.thomascookgroup.ca%2ftcdevelopment%2ftcna%2fgetcurrency.asp%3fratetype%3dSTANDARD%26byCurrency%3dY",
			success: function(data){
				var xmlRatesNode = $j(data).find("CURRENCY");
				var strRatesOutput = "";
				if ($j(xmlRatesNode).length > 0) {
					var intNodeCounter = 0;
					$j(xmlRatesNode).each(function(){
						if (intNodeCounter % 2 == 0) {
							strRatesOutput = strRatesOutput + "<tr>";
						} else {
							strRatesOutput = strRatesOutput + "<tr class=\"tc_odd\">";
						}
						strRatesOutput = strRatesOutput + "<th scope=\"row\"><img src=\"" + $j(this).find("ICON").text() + "\" alt=\"" + $j(this).find("CURRENCY_DESC").text() + "\" /> " + $j(this).find("CURRENCY_DESC").text() + "</th>";
						//strRatesOutput = strRatesOutput + "<th scope=\"row\">" + $j(this).find("CURRENCY_DESC").text() + "</th>";
						strRatesOutput = strRatesOutput + "<td>" + $j(this).attr("buyrate") + "</td>";
						strRatesOutput = strRatesOutput + "<td>" + $j(this).attr("sellrate") + "</td>";
						strRatesOutput = strRatesOutput + "</tr>";
						intNodeCounter++;
					});
					strRatesOutput = "<table class=\"tc_foreign_exchange\"><thead><tr><th class=\"tc_first\">Monnaie</th><th>Taux d'achat</th><th>Taux de vente</th></tr></thead><tfoot><tr><td colspan=\"3\"><span>Mis ? jour tous les jours ? 8 AM HNE</span></td></tr></tfoot><tbody>" + strRatesOutput + "</tbody></table>";
				} else {
					strRatesOutput = "We're sorry, foreign exchange rates are not available at this time. Please try again later.";
				}
				$j("div#tc_foreign_exchange_all").html(strRatesOutput);
				tb_show("Taux de change de devises","#TB_inline?height=400&width=500&inlineId=tc_foreign_exchange_all","");
			},
			error: function(XMLHttpRequest, textStatus, errorThrown){
				//alert(errorThrown);
			},
			dataType: "xml"
		});
	} else {
		tb_show("Taux de change de devises","#TB_inline?height=400&width=500&inlineId=tc_foreign_exchange_all","");
	}
}

function checkAvailabilityThickBox(objDepartureDate, bookingString, retDate) {  
//	if (TCNA.Utils.isValidDate($j(objDepartureDate).val())) {
		//var dtDepartureDate = new Date($j(objDepartureDate).val())
//alert(objDepartureDate);
//		bookingString = bookingString + "&date_dep=" + TCNA.Utils.padZero(dtDepartureDate.getMonth()+1) + "/" + //TCNA.Utils.padZero(dtDepartureDate.getDate()) + "/" + dtDepartureDate.getFullYear();

if (TCNA.Utils.isValidDate(objDepartureDate)) {
			var dtDepDateDate = new Date(objDepartureDate)
			bookingString = bookingString + "&date_dep=" + TCNA.Utils.padZero(dtDepDateDate.getMonth()+1) + "/" + TCNA.Utils.padZero(dtDepDateDate.getDate()) + "/" + dtDepDateDate.getFullYear();
			  


		if (TCNA.Utils.isValidDate(retDate)) {
			var dtReturnDate = new Date(retDate)
			bookingString = bookingString + "&date_ret=" + TCNA.Utils.padZero(dtReturnDate.getMonth()+1) + "/" + TCNA.Utils.padZero(dtReturnDate.getDate()) + "/" + dtReturnDate.getFullYear();
		}	  
		bookingString = bookingString + "?KeepThis=true&amp;TB_iframe=false&amp;height=430&amp;width=500&reload=true";
		tb_OpenById(bookingString);
	} else {
		alert("The date is not valid, please contact us for more info.");
		return false;
	}
}


function checkAvailabilityThickBoxPA(objDepartureDate, bookingString, retDate) {  
	if (TCNA.Utils.isValidDate($j(objDepartureDate).val())) {
var dtDepartureDate = new Date($j(objDepartureDate).val())

		bookingString = bookingString + "&date_dep=" + TCNA.Utils.padZero(dtDepartureDate.getMonth()+1) + "/" + TCNA.Utils.padZero(dtDepartureDate.getDate()) + "/" + dtDepartureDate.getFullYear();

		if (TCNA.Utils.isValidDate(retDate)) {
			var dtReturnDate = new Date(retDate)
			bookingString = bookingString + "&date_ret=" + TCNA.Utils.padZero(dtReturnDate.getMonth()+1) + "/" + TCNA.Utils.padZero(dtReturnDate.getDate()) + "/" + dtReturnDate.getFullYear();
		}	  
		bookingString = bookingString + "?KeepThis=true&amp;TB_iframe=false&amp;height=430&amp;width=500&reload=true";
		tb_OpenById(bookingString);
	} else {
		alert("The date is not valid, please contact us for more info.");
		return false;
	}


}


function checkAvailabilityThickBoxPA(objDepartureDate, bookingString, retDate) {  
	if (TCNA.Utils.isValidDate($j(objDepartureDate).val())) {
var dtDepartureDate = new Date($j(objDepartureDate).val())

		bookingString = bookingString + "&date_dep=" + TCNA.Utils.padZero(dtDepartureDate.getMonth()+1) + "/" + TCNA.Utils.padZero(dtDepartureDate.getDate()) + "/" + dtDepartureDate.getFullYear();

		if (TCNA.Utils.isValidDate(retDate)) {
			var dtReturnDate = new Date(retDate)
			bookingString = bookingString + "&date_ret=" + TCNA.Utils.padZero(dtReturnDate.getMonth()+1) + "/" + TCNA.Utils.padZero(dtReturnDate.getDate()) + "/" + dtReturnDate.getFullYear();
		}	  
		bookingString = bookingString + "?KeepThis=true&amp;TB_iframe=false&amp;height=430&amp;width=500&reload=true";
		tb_OpenById(bookingString);
	} else {
		alert("The date is not valid, please contact us for more info.");
		return false;
	}


}

function launchPhotoGallery(whichPhotoList) {
	var strPhotoList = document.getElementById(whichPhotoList).value;
	var arrPhotoList = strPhotoList.split("|");
	if ($j("div#tc_photosOverlayContainer").length == 0) {
		$j("body").append("<div id=\"tc_photosOverlayContainer\"></div>");
		$j("div#tc_photosOverlayContainer").css({"position":"absolute","top":"-3000px"});
	}
	$j("a.thickbox").unbind("click");
	$j("div#tc_photosOverlayContainer").html("");
	var strPhotoLinks = "";
	for (x=1; x<arrPhotoList.length; x++) {
		//$j("div#tc_photosOverlayContainer").append("<a class=\"thickbox\" href=\"" + arrPhotoList[x] + "\" rel=\"gallery_" + whichPhotoList + "\"><img src=\"" + arrPhotoList[x] + "\" /></a>");
		strPhotoLinks = strPhotoLinks + "<a class=\"thickbox\" href=\"" + arrPhotoList[x] + "\" rel=\"gallery_" + whichPhotoList + "\"><img src=\"" + arrPhotoList[x] + "\" /></a>";
	}
	strPhotoLinks = "<a id=\"photoOverlayLink\" class=\"thickbox\" href=\"" + arrPhotoList[0] + "\" rel=\"gallery_" + whichPhotoList + "\"><img src=\"" + arrPhotoList[0] + "\" /></a>" + strPhotoLinks;
	//$j("div#tc_photosOverlayContainer").append("<a id=\"photoOverlayLink\" class=\"thickbox\" href=\"" + arrPhotoList[0] + "\" rel=\"gallery_" + whichPhotoList + "\"><img src=\"" + arrPhotoList[0] + "\" /></a>");
	$j("div#tc_photosOverlayContainer").html(strPhotoLinks);
	tb_init("a.thickbox");
	$j("div#tc_photosOverlayContainer a#photoOverlayLink").click();
}

function isValidEmail(thisEmail) {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(thisEmail);
}

function validateEmail(whichForm){	
	$j(whichForm).find("p.tc_error").remove();
	$j(whichForm).removeClass("tc_error");
	if (isValidEmail($j(whichForm).find("input[type='text']").val())){
		return true;
	} else {
		$j(whichForm).addClass("tc_error");
		$j(whichForm).append("<p class=\"tc_error\"><br><br><br><font color=red>Veuillez entrer une adresse courriel valide.</font></p>");
		return false;
	}
}

function showItemMap(latVal, longVal, thisElement){
	$j(thisElement).parent().find("div.tc_item_gmap_static").slideDown("fast");
	$j(thisElement).hide();
}

function processDeptCitySelect_TopDest(whichElement) {
	//keep current context of dropdowns based on hidden fields
	//make ajax request and populate content
	deleteMapOverlays();
	getTopTrendDealItems($j("option:selected", whichElement).val());
}

function setSelectedTrendDealItem(whichItem) {
	$j("#tc_top_trending_deals_content div.tc_left ul li").removeClass("tc_selected");
	$j("#tc_top_trending_deals_content div.tc_left ul li img").attr("src", function(){
		return this.src.replace("_blue_", "_gold_");
	});
	$j("#tc_top_trending_deals_content div.tc_left ul li").eq(whichItem).addClass("tc_selected");
	$j("#tc_top_trending_deals_content div.tc_left ul li").eq(whichItem).find("img").attr("src", function(){
		return this.src.replace("_gold_", "_blue_");
	});
	//update marker pin: replace current pin with default gold, set new pin to blue
	markersArray[intCurrentMarker].setIcon("http://images2.thomascookgroup.ca/thomascookCA/searsTravel/en/images/pin_gold_" + (intCurrentMarker+1) + ".png");
	intCurrentMarker = whichItem;
	markersArray[intCurrentMarker].setIcon("http://images2.thomascookgroup.ca/thomascookCA/searsTravel/en/images/pin_blue_" + (intCurrentMarker+1) + ".png");
	map.panTo(markersArray[whichItem].getPosition());
}

function deleteMapOverlays() {
	if (markersArray.length > 0) {
		for (i=0; i < markersArray.length; i++) {
			markersArray[i].setMap(null);
		}
		markersArray.length = 0;
	}
}

function setSelectedTrendDealMapItem(marker, whichItem) {
	google.maps.event.addListener(marker, "click", function(){
		//add click event to marker to highlight left column item
		setSelectedTrendDealItem(whichItem);
		map.panTo(markersArray[whichItem].getPosition());
	});
}

function formatDestinationFileName(strName){
	strName = strName.substring(0, strName.indexOf(","));
	strName = strName.toLowerCase();
	strName = strName.replace(/'/g,"");
	strName = strName.replace(/ /g,"-");
	var objDestFileNameLookup = new Object();
	objDestFileNameLookup["punta-cana"] = "/fr/dominican-republic-travel/packages-to-punta-cana";
	objDestFileNameLookup["orlando"] = "/fr/usa-travel/orlando-vacations";
	objDestFileNameLookup["riviera-maya"] = "/fr/mexico-travel/packages-to-riviera-maya";
	objDestFileNameLookup["varadero"] = "/fr/cuba-travel/packages-to-varadero";
	objDestFileNameLookup["nassau"] = "/fr/packages-to-bahamas";
	objDestFileNameLookup["aruba"] = "/fr/packages-to-aruba";
	objDestFileNameLookup["cancun"] = "/fr/mexico-travel/packages-to-cancun";
	objDestFileNameLookup["rome"] = "/fr/travel-to-italy";
	objDestFileNameLookup["venice"] = "/fr/travel-to-italy";
	objDestFileNameLookup["montego-bay"] = "/fr/jamaica-travel/packages-to-montego-bay";
	objDestFileNameLookup["cayo-coco"] = "/fr/cuba-travel/packages-to-cayo-coco";
	objDestFileNameLookup["los-cabos"] = "/fr/mexico-travel/packages-to-los-cabos";
	objDestFileNameLookup["las-vegas"] = "/fr/usa-travel/las-vegas-vacations";			objDestFileNameLookup["holguin"] = "/fr/cuba-travel/packages-to-holguin";
	objDestFileNameLookup["puerto-vallarta"] = "/fr/mexico-travel/packages-to-puerto-vallarta";
	objDestFileNameLookup["santa-clara"] = "/fr/cuba-travel/packages-to-santa-clara";
	objDestFileNameLookup["london"] = "/fr/travel-to-england";
	if (objDestFileNameLookup[strName] != "") {
		return objDestFileNameLookup[strName];
	} else {
		return strName;
	}							
}

/*function initializeDefaultTrendsMap() {
	if (map == "") {
		myOptions = {
			center: new google.maps.LatLng(54.927142, -99.228516),
			mapTypeId: google.maps.MapTypeId.ROADMAP
		};
		map = new google.maps.Map(document.getElementById("tc_top_trending_deals_map"), myOptions);
	}
}*/


function initializeListingMaps(){
	$j("div.tc_deals_listing_item a.tc_map_link").unbind("click");
	$j("div.tc_item_gmap_static a").unbind("click");
	$j("div.tc_deals_listing_item a.tc_map_link").click(function(event){
		$j(this).parent().find("div.tc_item_gmap_static").slideDown("fast");
		$j(this).hide();
		event.preventDefault();
	});
	$j("div.tc_item_gmap_static a").click(function(event){
		$j(this).parent().slideUp("fast").parent().find("a.tc_map_link").show();
		event.preventDefault();
	});
}

function moveToPage(whichPoundCode, whichElement){
	//use the passed pound code to call the WSRenderer and whichElement to target the appropriate parent container as a target
	var objListingContainer = $j(whichElement).parents("div.tc_deals_listing_content");
	whichPoundCode = whichPoundCode.replace(/=/g, "%3d");
	whichPoundCode = whichPoundCode.replace(/&/g, "%26");
	$j.ajax({
		url: "http://" + HostName + "/Pages/Admin/WSRenderer.aspx?hotdealcode=%23%23%23%23" + whichPoundCode + "%23%23%23%23",
		success: function(data){
			$j(objListingContainer).html($j(data));
			$j("a.thickbox").unbind("click");
			tb_init("a.thickbox");
			$j("div#tc_photosOverlayContainer").html("").hide();
			initializeListingMaps();
			if ($j("div.tc_deals_listing_content").length > 1) {
				if ($j("div.tc_tabbed_navigation li.tc_selected a").text().indexOf("Vacation") >= 0) {
					updateDestinationsResultsListSummary("VACATIONS");
				} else if ($j("div.tc_tabbed_navigation li.tc_selected a").text().indexOf("Flight") >= 0) {
					updateDestinationsResultsListSummary("FLIGHTS");
				}
			} else {
				updateResultsListSummary();
			}
			$j.scrollTo("div#tc_deals_listing");
		},
		error: function(XMLHttpRequest, textStatus, errorThrown){
//			alert(errorThrown);
		},
		dataType: "html"
	});
}

function updateResultsListSummary(){
	if ($j("input#resultsStart").length > 0) {
		$j("div.tc_listing_header span.tc_results span span").html($j("input#resultsStart").val() + "-" + $j("input#resultsEnd").val());
		$j("div.tc_listing_header span.tc_results strong").html($j("input#resultsTotal").val());
		$j("div.tc_listing_header form span.tc_results").css("visibility","visible");
		$j("div.tc_listing_header form label.tc_sortfilter").css("visibility","visible");
	} else {
		$j("div.tc_listing_header form span.tc_results").css("visibility","hidden");
		$j("div.tc_listing_header form label.tc_sortfilter").css("visibility","hidden");
	}
}

function updateDestinationsResultsListSummary(whichContext){
	var objContext =  $j("div#tc_deals_listing_" + whichContext.toLowerCase() + "_content");
	if ($j(objContext).find("input#resultsStart").length > 0) {
		$j("div.tc_listing_header span.tc_results span span").html($j(objContext).find("input#resultsStart").val() + "-" + $j(objContext).find("input#resultsEnd").val());
		$j("div.tc_listing_header span.tc_results strong").html($j(objContext).find("input#resultsTotal").val());
		$j("div.tc_listing_header form span.tc_results").css("visibility","visible");
		$j("div.tc_listing_header form label.tc_sortfilter").css("visibility","visible");
	} else {
		$j("div.tc_listing_header form span.tc_results").css("visibility","hidden");
		$j("div.tc_listing_header form label.tc_sortfilter").css("visibility","hidden");
	}
}
