﻿window.scrollTo = function() { };

// set flash detection
var requiredMajorVersion = 8;
var requiredMinorVersion = 0;
var requiredRevision = 0;
var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
var rotateTimer;

// set scrolling indexs
homeminindex = 1;
homemaxindex = 0; //loaded from code
homeimageindex = 1;

offerminindex = 0;
offermaxindex = 0; //loaded from code
offerimageindex = 0;

galleryminindex = 1;
gallerymaxindex = 2; //loaded from code
galleryimageindex = 1;


//function showErrors(valGroup)
//{
//    if (!Page_ClientValidate(valGroup))
//    {
//        $('.errorpanel').show();
//    }
//}

function cleardefault(obj, value) {
    if (obj.value == value)
        obj.value = "";
}

function checkAll(obj) {
    for (i = 0; i < document.aspnetForm.elements.length; i++) {
        if (document.aspnetForm.elements[i].type == "checkbox") {
            document.aspnetForm.elements[i].checked = obj.checked;
        }
    }
}

function selectTab(tabID, index) {

    var $tabs = $(tabID).tabs();
    $tabs.tabs('select', index - 1); // switch to tab
}

function rotateTab() {
    if ($(".heroscroller").length > 0) {

        $(".heroscroller .pages li a").get(homeimageindex).setAttribute("class", "");
        $(".heroscroller .pages li a").get(homeimageindex).setAttribute("className", "");

        if (homeimageindex < homemaxindex) {
            homeimageindex += 1;
        }
        else {
            homeimageindex = 1;
        }

        //update image
        var largePath = $(".heroscroller .pages li a").get(homeimageindex);
        var largeRel = $(".heroscroller .pages li a").get(homeimageindex).rel;
        var largeAlt = $(".heroscroller .pages li a").get(homeimageindex).title;

        $('.heroscroller').fadeTo('fast', 0);

        $('#homeimage').fadeTo('slow', 0.1, function() {
            $('#homeimage').attr({ src: largeRel, alt: largeAlt });
            $('#homeimagelnk').attr({ href: largePath });

            $(".heroscroller .pages li a").get(homeimageindex).setAttribute("class", "on");
            $(".heroscroller .pages li a").get(homeimageindex).setAttribute("className", "on");

            $('#homeimage').fadeTo('slow', 1, function() { $('.heroscroller').fadeTo('fast', 1); });

        });

        //reset timer//
        rotateTimer = setTimeout('rotateTab()', 10000);
    }
}


//function uncheckMain(obj)
//{
//    alert(obj.checked);
//    //main.checked = false;
//}

$().ready(function() {

    // HIDE on page load
    $("#DayByDayRHS").hide();
    $("#DatesAvailability").hide();

    $('#accordianlist').accordion({
        header: 'div.title',
        active: '.selected',
        alwaysOpen: false,
        autoheight: false
    });

    // simple accordion
    $('#faqAccordian').accordion({
        active: '.selected'
    });

    // Expand all simple accordian
    $('#FAQExpandAll').click(function() {
        $(".basicaccordian:not(:has(.selected))").accordion("activate", 0);
        return false;
    });

    // colapse all simple accordian
    $('#FAQCollapseAll').click(function() {
        $("#faqAccordian").accordion("activate", -1);
        return false;
    });



    $('ul.nav').superfish({
        autoArrows: false,                           // disable generation of arrow mark-up 
        dropShadows: false,                            // disable drop shadows 
        delay: 500,                            // one second delay on mouseout 
        animation: { opacity: 'none', height: 'show' },  // fade-in and slide-down animation 
        speed: 'fast'                          // faster animation speed
    });

    // tabify
    jQuery('#tabs').tabs();
    jQuery('#seasons').tabs();
    jQuery('#travellers').tabs();

    // Catch ajax call ended
    if (Sys != undefined)
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);

    function EndRequestHandler(sender, args) {
        if ($('#travellers')[0] != null) {
            $('#travellers').tabs();
        }
    }

    // Book now button click function to show Dates and Availablity tab detail
    $('#book-now').click(function() { // bind click event to link
        var $tabs = $('#tabs').tabs();
        var list = $tabs.children('.tabcontainer').children('ul');
        var tablist = $('li:has(a[href])', list);

        $tabs.tabs('select', (tablist.length / 2) - 1); // switch to forth tab

        // Collapse accordian
        var index = (tablist.length / 2) - 1;

        if (index == dates)
            $("#accordianlist").accordion("activate", -1);
        else
            $("#accordianlist").filter(":not(:has(.selected))").accordion("activate", 0);

        return false;
    });

    // How to Book  button click function to show Dates and Availablity tab detail
    $('#howtobook').click(function() { // bind click event to link
        var $tabs = $('#tabs').tabs();
        var list = $tabs.children('.tabcontainer').children('ul');
        var tablist = $('li:has(a[href])', list);

        $tabs.tabs('select', (tablist.length / 2) - 1); // switch to forth tab

        // Collapse accordian
        var index = (tablist.length / 2) - 1;

        if (index == dates)
            $("#accordianlist").accordion("activate", -1);
        else
            $("#accordianlist").filter(":not(:has(.selected))").accordion("activate", 0);

        return false;
    });

    // Main Tab clicked - function to show hide accordian group on RHS
    $('.pagetabs ul li a').click(function() { // bind click event to link
        // undeclared Variables are declared in "tour.aspx" from codebehind

        var index = $('.pagetabs ul li a').index(this);

        // Collapse accordian
        if (index == daybyday || index == dates) {
            $("#accordianlist").accordion("activate", -1);

            if (index == daybyday) {
                $("#DayByDayRHS").show();
                $("#DatesAvailability").hide();
            }

            if (index == dates) {
                $("#DayByDayRHS").hide();
                $("#DatesAvailability").show();
            }
        }
        else {
            $("#accordianlist").filter(":not(:has(.selected))").accordion("activate", 0);

            $("#DayByDayRHS").hide();
            $("#DatesAvailability").hide();
        }

        return false;
    });

    // rotate Experiance icons
    $('#ExpRight').rotate({ angle: 15 });
    $('#ExpLeft').rotate({ angle: -15 });

    //homepage scrollering feature images
    $(".heroscroller .pages li a").click(function() {

        // Resetting selected class
        $(".heroscroller .pages li a").get(homeimageindex).setAttribute("class", "");
        $(".heroscroller .pages li a").get(homeimageindex).setAttribute("className", "");

        // getting index of clicked href
        if ($(this).attr("class") == "prev") {
            if (homeimageindex > homeminindex) {
                homeimageindex -= 1;
            }
        }
        else if ($(this).attr("class") == "next") {
            if (homeimageindex < homemaxindex) {
                homeimageindex += 1;
            }
        }
        else {
            homeimageindex = $(".heroscroller .pages li a").index(this);
        }

        // get path and title of clicked href
        var largePath = $(".heroscroller .pages li a").get(homeimageindex);
        var largeRel = $(".heroscroller .pages li a").get(homeimageindex).rel;
        var largeAlt = $(".heroscroller .pages li a").get(homeimageindex).title;
        // set selected class
        $(".heroscroller .pages li a").get(homeimageindex).setAttribute("class", "on");
        $(".heroscroller .pages li a").get(homeimageindex).setAttribute("className", "on");

        // change image src and title
        $("#homeimage").attr({ src: largeRel, alt: largeAlt });
        $('#homeimagelnk').attr({ href: largePath });


        clearTimeout(rotateTimer);

        return false;
    });

    //reset timer//
    rotateTimer = setTimeout('rotateTab()', 10000);

    // latest offer scrolling images
    $(".latestoffer .pages li a").click(function() {

        // Resetting selected class
        $(".latestoffer .pages li a.offerlink").get(offerimageindex).setAttribute("class", "offerlink");
        $(".latestoffer .pages li a.offerlink").get(offerimageindex).setAttribute("className", "offerlink");

        // getting index of clicked href
        if ($(this).attr("class") == "prev") {
            if (offerimageindex > offerminindex) {
                offerimageindex -= 1;
            }
        }
        else if ($(this).attr("class") == "next") {
            if (offerimageindex < offermaxindex) {
                offerimageindex += 1;
            }
        }
        else {
            offerimageindex = $(".latestoffer .pages li a.offerlink").index(this);
        }

        // get path and title of clicked href
        var largeURL = $(".latestoffer .pages li a.offerimg").get(offerimageindex);
        var largePath = $(".latestoffer .pages li a.offerlink").get(offerimageindex);
        var largeAlt = $(".latestoffer .pages li a.offerlink").get(offerimageindex).title;

        // set selected class
        $(".latestoffer .pages li a.offerlink").get(offerimageindex).setAttribute("class", "offerlink on");
        $(".latestoffer .pages li a.offerlink").get(offerimageindex).setAttribute("className", "offerlink on");

        // change image src and title
        $("#offerimage").attr({ src: largePath, alt: largeAlt });
        $("#offerlink").attr({ href: largeURL, alt: largeAlt });

        return false;
    });

    // latest offer scrolling images
    $(".gallery .pages li a").click(function() {

        // Resetting selected class
        $(".gallery .pages li a").get(galleryimageindex).setAttribute("class", "");
        $(".gallery .pages li a").get(galleryimageindex).setAttribute("className", "");

        // getting index of clicked href
        if ($(this).attr("class") == "prev") {
            if (galleryimageindex > galleryminindex) {
                galleryimageindex -= 1;
            }
        }
        else if ($(this).attr("class") == "next") {
            if (galleryimageindex < gallerymaxindex) {
                galleryimageindex += 1;
            }
        }
        else {
            galleryimageindex = $(".gallery .pages li a").index(this);
        }

        // get path and title of clicked href
        var largePath = $(".gallery .pages li a").get(galleryimageindex);
        var largeAlt = $(".gallery .pages li a").get(galleryimageindex).title;

        // set selected class
        $(".gallery .pages li a").get(galleryimageindex).setAttribute("class", "on");
        $(".gallery .pages li a").get(galleryimageindex).setAttribute("className", "on");

        // change image src and title
        $("#galleryimage").attr({ src: largePath, alt: largeAlt });

        return false;
    });

    $(".newsletter").colorbox({
        innerWidth: 480,
        innerHeight: 360,
        iframe: true,
        overlayClose: false,
        scrolling: false,
        //onComplete: function() { $(this).colorbox.resize(); },
        onOpen: function() { $(this).colorbox({ href: "/signup-popup.aspx?val=1" }) }
    });

    $("#hlInfCountry").colorbox({ width: "30%", inline: true, href: "#infoCountry" });
    $("#hlInfExp").colorbox({ width: "30%", inline: true, href: "#infoExperience" });
    $("#hlInfPrice").colorbox({ width: "30%", inline: true, href: "#infoPriceRange" });
    $("#hlInfKeyword").colorbox({ width: "30%", inline: true, href: "#infoKeywords" });
    $("#hlInfDuration").colorbox({ width: "30%", inline: true, href: "#infoDuration" });
    $("#hlTerms").colorbox({ width: "30%", inline: true, href: "#infoTerms" });

    $("#hlPrivacyPolicy").colorbox({ width: "50%", height: "50%", iframe: true });
    $("#hlSecurityPolicy").colorbox({ width: "50%", height: "50%", iframe: true });

    $(".tellfriend").colorbox({ innerWidth: "390px", innerHeight: "400px", overlayClose: false, iframe: true });
    
    
    // Generic colorbox
    $(".enlarge").colorbox();

    // Video gallery colorbox
    $(".vidBox").colorbox({iframe:true, innerWidth:440, innerHeight:400});
    

});
