﻿// Displays the getaway wizard modal
function openGetawayWizard() {
    $.colorbox({ width: "700px", opacity: ".8", inline: true, href: "#getaway-wizard" });
}

// Displays the send to friend modal
function openSendToFriend() {
    $.colorbox({ width: "500px", opacity: ".8", inline: true, href: "#send-to-friend" });
}

function openSendToAFriendMain() {
    $.colorbox({ width: "700px", height: "440px", opacity: ".8", inline: true, href: "#send-to-friend-main" });
}

function openWeatherPopup() {
    $.colorbox({ width: "300px", height: "220px", opacity: ".8", inline: true, href: "#weather-popup" });
}

// Redirects tot he getaway wizard results after the filtering process is successful
function redirectToGetawayWizardResults(ajaxContent) {
    var status = ajaxContent.get_response().getResponseHeader('X-validated');
    var url = ajaxContent.get_response().getResponseHeader('X-url');

    if (status == 'True') {
        window.location.replace(url);
    }
}

function initializeCalendar() {
    $('input.calendar').datepicker();
}

function defaultText(textbox, text) {
    var elem = $(textbox);

    elem.click(function() {
        if ($(this).val() == text)
            $(this).val('');
    });

    elem.blur(function() {
        if ($(this).val() == '')
            $(this).val(text);
    });
}

function SmartCheckBox(containerid) {
    $(containerid + ' input[type=checkbox]').click(function() {
        var choice = ' input.choice';
        var all = ' input.all';
        var chk = 'checked';
        var ischk = ':' + chk;
        var clicked = $(this);

        if (clicked.is('.all')) { // clicked on all
            if (clicked.is(ischk))
                $(containerid + choice).removeAttr(chk);
            else
                $(containerid + all).attr(chk, chk);
        } else { // click on a choice other than all
            var flag = true;
            if (clicked.is(ischk)) { // just checked
                $(containerid + choice).each(function() {
                    if (!$(this).is(ischk)) flag = false;
                });
                if (flag) { // all checked, then -> all
                    $(containerid + all).attr(chk, chk);
                    $(containerid + choice).removeAttr(chk);
                } else { // at least one choice is checked
                    $(containerid + all).removeAttr(chk);
                }
            } else { // just unchecked
                $(containerid + choice).each(function() {
                    if ($(this).is(ischk)) flag = false;
                });
                if (flag) // all unchecked, then -> all
                    $(containerid + all).attr(chk, chk);
                else  // at least one choice is not checked
                    $(containerid + all).removeAttr(chk);
            }
        }
    });
}

// Map functions
$(document).ready(function() {
    defaultText('#search-text', 'Search');
    initializemarquee();
});

function glassOnMouseOver(img_id, left, top) {
    $(img_id).attr("src", "/assets/img/map-glass-hover.png");
    $(img_id).css("left", left);
    $(img_id).css("top", top);
}

function glassOnMouseOut(img_id, left, top) {
    $(img_id).attr("src", "/assets/img/map-glass.png");
    $(img_id).css("left", left);
    $(img_id).css("top", top);
}

function openMapLinks(left, top) {

    var config = {
        over: onLinksOver, // function = onMouseOver callback (REQUIRED)    
        timeout: 1000, // number = milliseconds delay before onMouseOut    
        out: onLinksOut // function = onMouseOut callback (REQUIRED)    
    };

    $('#map-links-container').hoverIntent(config)
    
    var height = $('#map-links-container').height();

    if (height + top > 380) {
        var overflow = height + top - 380;

        if (overflow > top) {
            $('#map-links-container').css("top", '0px');
        }
        else {
            $('#map-links-container').css("top", (top - overflow) + 'px');
        }
    }
    else {
        $('#map-links-container').css("top", top + 'px');
    }
    
    $('#map-links-container').css("left", left + 'px');
    
    $('#map-links-container').fadeIn(500);
}

function closeMapLinks() {
    $('#map-links-container').fadeOut(500);
}

function onLinksOver() {

}

function onLinksOut() {
    $(this).fadeOut(500);
}

// Callback for the carousel filmstrip
function mycarousel_initCallback(carousel) {
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto(2);
    });
};

// filmstrip items
function filmstripOnMouseOver(img_id, imagePath) {
    $(img_id).attr("src", imagePath);
}

function filmstripOnMouseOut(img_id, imagePath) {
    $(img_id).attr("src", imagePath);
}


/***********************************************
* Cross browser Marquee II- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/

var delayb4scroll = 2000 //Specify initial delay before marquee starts to scroll on page (2000=2 seconds)
var marqueespeed = 1 //Specify marquee scroll speed (larger is faster 1-10)
var pauseit = 1 //Pause marquee onMousever (0=no. 1=yes)?

////NO NEED TO EDIT BELOW THIS LINE////////////

var copyspeed = marqueespeed
var pausespeed = (pauseit == 0) ? copyspeed : 0
var actualheight = ''

function scrollmarquee() {
    if (parseInt(cross_marquee.style.top) > (actualheight * (-1) + 8))
        cross_marquee.style.top = parseInt(cross_marquee.style.top) - copyspeed + "px"
    else
        cross_marquee.style.top = parseInt(marqueeheight) + 8 + "px"
}

function initializemarquee() {
    if (!document.getElementById("vmarquee"))
        return
    cross_marquee = document.getElementById("vmarquee")
    cross_marquee.style.top = 0
    marqueeheight = document.getElementById("marqueecontainer").offsetHeight
    actualheight = cross_marquee.offsetHeight
    if (window.opera || navigator.userAgent.indexOf("Netscape/7") != -1) { //if Opera or Netscape 7x, add scrollbars to scroll and exit
        cross_marquee.style.height = marqueeheight + "px"
        cross_marquee.style.overflow = "scroll"
        return
    }
    setTimeout('lefttime=setInterval("scrollmarquee()",30)', delayb4scroll)
    $('#marqueecontainer').css('position', 'relative');
}



// -->
