﻿//¤¤¤ ON LOAD EVENTS ¤¤¤

$(document).ready(function () {

    //Load Roll overs effects
    RollHoverEffects();

    //Used in the product template
    VerticalCenteringForIE();

    //Forms - Validation
    $("form").validity(function () {
        $(".textbox.require").require();
        $(".txtemail").require().match("email");
        $(".txttelephone").require().match("phone");
    });
	
	$(".booking.booking1 .booking-button.imagehover").live('click', function ()
	{
		$(".textbox.require").remove();
        $(".txtemail").require().remove();
        $(".txttelephone").require().remove();
	});

    //Forms - French Language Pack for jValidity
    if (ReturnLanguage() == "fr") { $.extend($.validity.messages, { require: "Ce champ est requis.", phone: "Ce champ doit être de format ###-###-####", email: "Ce champ doit être un adresse courriel" }); }

    //Forms - Add effect when you just sent an form request. 
    $(".form-confirmation").effect("pulsate", { times: 3 }, 1000);

    //Make some input controls pretty. All those with the class .uniform
    $(".uniform, .smalluniform, .verysmalluniform").uniform();

    $(".uniform").siblings().addClass("spanuniform");
    $(".smalluniform").siblings().addClass("spansmalluniform");
    $(".verysmalluniform").siblings().addClass("spanverysmalluniform");

    $('.datepicker').datepicker();
	
    $("#recaptcha_table img:first").appendTo('#_divImgCaptcha');

    //Hover for hotel box
    $(".hotelbox, .kezaccordion, .rooms, .hoverchk").hover(function () { $(this).stop().animate({ backgroundColor: "#f6dfb9" }, 'fast'); }, function () { $(this).stop().animate({ backgroundColor: "#fcfcfc" }, 'fast'); });

    //Booking Tabs
    if ($.browser.msie) { var fadedelay = 0; };
    $('.btnTab1').click(function () {

        if ($.browser.msie) { $('.btnTab1').attr("src", $('.btnTab1').attr("src").replace("-off.", "-on.")); }
        else { $('.btnTab1').stop(true, true).fadeTo(0, 0.5, function () { $('.btnTab1').attr("src", $('.btnTab1').attr("src").replace("-off.", "-on.")).fadeTo(fadedelay, 1); }); }

        $('.btnTab2').attr("src", $('.btnTab2').attr("src").replace("-on.", "-off."));
        $('.btnTab3').attr("src", $('.btnTab3').attr("src").replace("-on.", "-off."));

        $('.booking1').stop(true, true).fadeIn(fadedelay);
        $('.booking2').stop(true, true).fadeOut(fadedelay);
        $('.booking3').stop(true, true).fadeOut(fadedelay);
    });

    $('.btnTab2').click(function () {

        if ($.browser.msie) { $('.btnTab2').attr("src", $('.btnTab2').attr("src").replace("-off.", "-on.")); }
        else { $('.btnTab2').stop(true, true).fadeTo(0, 0.5, function () { $('.btnTab2').attr("src", $('.btnTab2').attr("src").replace("-off.", "-on.")).fadeTo(fadedelay, 1); }); }

        $('.btnTab1').attr("src", $('.btnTab1').attr("src").replace("-on.", "-off."));
        $('.btnTab3').attr("src", $('.btnTab3').attr("src").replace("-on.", "-off."));

        $('.booking2').stop(true, true).fadeIn(fadedelay);
        $('.booking1').stop(true, true).fadeOut(fadedelay);
        $('.booking3').stop(true, true).fadeOut(fadedelay);
    });

    $('.btnTab3').click(function () {

        if ($.browser.msie) { $('.btnTab3').attr("src", $('.btnTab3').attr("src").replace("-off.", "-on.")); }
        else { $('.btnTab3').stop(true, true).fadeTo(0, 0.5, function () { $('.btnTab3').attr("src", $('.btnTab3').attr("src").replace("-off.", "-on.")).fadeTo(fadedelay, 1); }); }

        $('.btnTab1').attr("src", $('.btnTab1').attr("src").replace("-on.", "-off."));
        $('.btnTab2').attr("src", $('.btnTab2').attr("src").replace("-on.", "-off."));

        $('.booking3').stop(true, true).fadeIn(fadedelay);
        $('.booking1').stop(true, true).fadeOut(fadedelay);
        $('.booking2').stop(true, true).fadeOut(fadedelay);
    });
    //END OF Booking Tabs



    /* Flight choice custom accordion*/
    $(".kezaccordion").click(function () {
        if ($(this).height() == 17) {
            var addheight = $(this).children('.flightrecap').height();

            $(".kezaccordion").stop(true, true).animate({ height: 17 }, 0);
            $(this).stop(true, true).animate({ height: 30 + addheight }, 0);
        }

        //Show all rooms
        $(".rooms").fadeIn(500);

        //Hide rooms for selected flight
        if ($(this).attr('id') == "flight2") { $("#room1").fadeOut(500); }
    });

    var addheight = $(".defaultopen").children('.flightrecap').height();
    $(".defaultopen").stop(true, true).animate({ height: 50 + addheight }, 400); //size is different because images are not yet loaded

    //$('.flightrecap').betterTooltip({ speed: 0, delay: 100 });

    $('input').hint();

    if ($.browser.msie) { $(".ieinspectorbug").removeAttr("style"); }

    $("table.flightrecap").hover(
    function () {
        $(this).siblings("#balloons").addClass("showballoon");
    },
    function () {
        $(this).siblings("#balloons").removeClass("showballoon");
    });


    $("#dest").change(function () {
        $.uniform.update();
    });

});


function RollHoverEffects()
{

    //.simplehover - Rollover effect on links
    $("a.simplehover img, img.simplehover").mouseover(function() {
        $(this).attr("src", $(this).attr("src").replace("-off.", "-on."));
    }).mouseout(function() {
        $(this).attr("src", $(this).attr("src").replace("-on.", "-off."));
    });


    //fadehover - Rollover effect on links and images with FADE
    $("a.fadehover img, img.fadehover").mouseover(function() {
        $(this).stop(true, true).fadeTo(0, 0.5, function() {
            $(this).attr("src", $(this).attr("src").replace("-off.", "-on.")).fadeTo(500, 1);
        });
    }).mouseout(function() {
        $(this).stop(true, true).fadeTo(50, 0.5, function() {
            $(this).attr("src", $(this).attr("src").replace("-on.", "-off.")).fadeTo(50, 1);
        });
    });


    //Effect on thumbnails images.
    $("a.imagehover img, img.imagehover, input.imagehover").mouseover(function() {
        $(this).stop().fadeTo(0, 0.35);
        $(this).stop().fadeTo(500, 1);
    });

}


//¤¤¤ FUNCTIONS & UTILITIES ¤¤¤

function ReturnLanguage() {
    language = $(location).attr('href').substr($(location).attr('href').indexOf('/', 7) + 1, 2);
    return language;
}

function VerticalCenteringForIE() {
    $(".category-image").load(function() {
        $(this).css("top", ($(this).parent().height() - $(this).height()) / 2);
    }).each(function() {
        if (this.complete) $(this).trigger("load"); //Patch for IE cached images
    });
}

//parse URL to get values  - To retrieve example : var i = getUrlVars()["i"];
function getUrlVars() {
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for (var i = 0; i < hashes.length; i++) {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}
