﻿/**
* @author - Dacia James Whittmanhart
* @copyright - 2010
**/

function isIE8() {
    if ((/msie 8./i).test(navigator.appVersion) == true) {
        return true;
    } else {
        return false;
    }
}

function isIE7() {
    if ((/msie 7./i).test(navigator.appVersion) == true) {
        return true;
    } else {
        return false;
    }
}

function isIE6() {
    if ((/msie 6./i).test(navigator.appVersion) == true) {
        return true;
    } else {
        return false;
    }
}

// flash intro collapse and set cookie so that flash appears only once per session
function introFlashFinishedPlaying() {
    $('.flashDiv').css('display', 'none');
    $.cookie("ILNY", "flash_intro");
};

function featureOn() {
    $(this).css('background-color', '#f2f0b8');
    $(this).children('.saveListing').css('display', 'block');
    var posResults = $(this).position();
    var widthResults = $(this).width();

    if ($(window).height() - window.mouseYPos <= 340) {
        $(this).children("div.stayResultRollover").css({ "left": (posResults.left + 30) + "px", "top": (posResults.top - 295) + "px" });
        $(this).children("div.stayResultRollover").css('display', 'block').addClass('displayUp');
        if ($(this).children('div.stayResultRollover').hasClass('displayUp')) {
            $(this).children('div.stayResultRollover').children('.resultRolloverBottom').css('display', 'block');
        } 
       //since IE has weird z-index stacking order, we have to reverse it
        if (isIE6()) {
            $(this).children("div.bubble").children("a").css('background-position', 'bottom left');
        }
    } else {
    if (isIE7() || isIE6()) {
            $(this).children("div.stayResultRollover").css({ "left": (posResults.left + 40) + "px", "top": (posResults.top + 30) + "px" });
        } else {
            $(this).children("div.stayResultRollover").css({ "left": (posResults.left + 30) + "px", "top": (posResults.top + 30) + "px" });
        }
        $(this).children("div.stayResultRollover").css('display', 'block');
        $(this).children('div.stayResultRollover').children('.resultRolloverBottom').css('display', 'none');
        if (isIE7() || isIE6()) {
            if (isIE6()) {
                var zIndexNumber = 5000;
                $('.stayResults .resultItemNoImg').css({ zIndex: '0' });
                $(this).css('zIndex', zIndexNumber);
                $(this).children("div.stayResultRollover").css('zIndex', zIndexNumber);
                $(this).children("div.bubble").children("a").css('background-position', 'bottom left');
            }
        } $("div.stayResultRollover").css({ zIndex: '5010' });
    }
};

function featureOff() {
    $(this).children('div.stayResultRollover').css('display', 'none').removeClass('displayUp');
    $(this).css('background-color', 'transparent');
    $(this).children('.saveListing').css('display', 'none');
    $(this).children("div.bubble").children("a").css('background-position', 'top left');
};


$(document).ready(function() {

    //PNG fix for IE6
    if (isIE6()) {
        $('#search_message').pngfix();
    }

    //suggestive search (global search bar) AND clear text on focus
    $("#search_field").focus(function() {
        $(this).removeClass("defaultTextColor");
    })
    .autocomplete(words, { matchSubset: 1, selectFirst: false })
    .blur(function() {
        if ($(this).val() == '') {
            $(this).addClass("defaultTextColor");
        }
    });

    //suggestive search for cities
    $(".cityInput").focus(function() {
        $(".cityInput").autocomplete(cities, { matchSubset: 1, selectFirst: false });
    });

    $(".cityInput").keydown(function() {
        $(".ac_results").addClass("cityAutocomplete");
    });

    $().mousemove(function(e) {
        window.mouseXPos = e.clientX;
        window.mouseYPos = e.clientY;
    });

    // Styled Select with Span
    if (!(isIE6())) {
        $("select.styled").css('opacity', '0').css('filter', 'alpha(opacity=0)');
    }

    $('div.pod').hover(function() {
        $(this).children('div.podtoggle').show();
        $(this).children('div.podtoggleOverlay').hide();
    }, function() {
        $(this).children('div.podtoggle').hide();
        $(this).children('div.podtoggleOverlay').show();
    });

    // Auto Select First Form Field on Page Load
    $('input[type="text"]:visible:first:not(.calendarInput, .cityInput)').focus();
    $('.orderBrochure input:visible:first').focus();
    $('.loginBlock input:visible:first').focus();

    //============Button Overlay=============================
    $('.imgOver').hover(function() {
        this.src = this.src.replace(".gif", "-over.gif");
        this.src = this.src.replace(".jpg", "-over.jpg");
        this.src = this.src.replace(".png", "-over.png");
    }, function() {
        this.src = this.src.replace("-over.gif", ".gif");
        this.src = this.src.replace("-over.jpg", ".jpg");
        this.src = this.src.replace("-over.png", ".png");
    });

    //=============Featured Destinations=======================
    $('.region1').mouseenter(function() {
        $(this).click(function() {
            $(this).parents('div:eq(1)').css('display', 'none');
            $(this).parents('div:eq(2)').children('div#popular1').css('display', 'block');
        });
    });
    $('.region2').mouseenter(function() {
        $(this).click(function() {
            $(this).parents('div:eq(1)').css('display', 'none');
            $(this).parents('div:eq(2)').children('div#popular2').css('display', 'block');
        });
    });
    $('.region3').mouseenter(function() {
        $(this).click(function() {
            $(this).parents('div:eq(1)').css('display', 'none');
            $(this).parents('div:eq(2)').children('div#popular3').css('display', 'block');
        });
    });
    $('.region4').mouseenter(function() {
        $(this).click(function() {
            $(this).parents('div:eq(1)').css('display', 'none');
            $(this).parents('div:eq(2)').children('div#popular4').css('display', 'block');
        });
    });
    $('.region5').mouseenter(function() {
        $(this).click(function() {
            $(this).parents('div:eq(1)').css('display', 'none');
            $(this).parents('div:eq(2)').children('div#popular5').css('display', 'block');
        });
    });

    //-------------------------------------------------------

    //home page new event hover function
    $('.highlightedDeal').hover(function() {
        $(this).css('backgroundColor', '#F2F0B8');
        $(this).children('.saveListing').css('display', 'block');
    }, function() {
        $(this).css('backgroundColor', 'transparent');
        $(this).children('.saveListing').css('display', 'none');
    });
    $('div.newEventSD').hover(function() {
        $(this).addClass('hoverListing');
        $(this).children('.saveListing').css('display', 'block');
    }, function() {
        $(this).removeClass('hoverListing');
        $(this).children('.saveListing').css('display', 'none');
    });
    $('div.newEventSD .saveListing').hover(function() {
        $(this).css('background-position', 'bottom left');
        $(this).children('a').css('background-position', 'bottom left');
    }, function() {
        $(this).css('background-position', 'top left');
        $(this).children('a').css('background-position', 'top left');
    });

    //------------------------------------------------------------
    var active_color = '#68665d'; // Colour of user provided text
    var inactive_color = '#68665d'; // Colour of default text
    var default_values = new Array();
    $("input.default-value").focus(function() {
        if (!default_values[this.id]) {
            default_values[this.id] = this.value;
        }
        if (this.value == default_values[this.id]) {
            this.value = '';
        }
        $(this).blur(function() {
            if (this.value == '') {
                this.value = default_values[this.id];
            }
        });
    });

    //--------Featured Rollover Function-----
    $(".stayResults").hoverIntent({
        sensitivity: 7,
        interval: 50,
        over: featureOn,
        timeout: 0,
        out: featureOff
    }).each(function() {
        if ($(this).children('a.stayResultsImage').children('img').length) {
            $(this).addClass("stayResultsWithImage");
            $(this).children('a.stayResultsImage').css('display', 'block').css('float', 'left').css('margin-right', '10px');
        }
    });

    //Checkboxes
    $('.refinerCheck').each(function() {
        $(this).hover(function() {
            $(this).css('background-color', '#FBD13E').css('background-position', '0 -15px');
        }, function() {
            $(this).css('background-color', 'transparent').css('background-position', 'left top');
        });
    });

    $('div.refinerCheck').live('click', function() {
        if ($(this).parents('div').children('input[name=amenitiesCheck]').attr("checked")) {
            $(this).parents('div').children('input[name=amenitiesCheck]').removeAttr("checked");
            $(this).removeClass("amenityBack");
        } else {
            $(this).parents('div').children('input[name=amenitiesCheck]').attr("checked", "checked");
            $(this).addClass("amenityBack");
        };
    });

    $('div.refinerCheck').live('click', function() {
        if ($(this).parents('div').children('input[name=themesCheck]').attr("checked")) {
            $(this).parents('div').children('input[name=themesCheck]').removeAttr("checked");
            $(this).removeClass("amenityBack");
        } else {
            $(this).parents('div').children('input[name=themesCheck]').attr("checked", "checked");
            $(this).addClass("amenityBack");
        };
    });

    $('div.refinerLink:not(.filterSubcat div.refinerLink)').live('mouseup', function() {
        if ($(this).parents('div').children('input.typeCheck').attr("checked")) {
            $(this).parents('div').children('input.typeCheck').removeAttr("checked");
            $(this).removeClass("refined");
        } else {
            $(this).parents('div').children('input.typeCheck').attr("checked", "checked");
            $(this).addClass("refined");
        };
    });

    //------------------------------------------------------------MAIN MENU
    $("#mainMenu li").hover(
        function() { $("ul", this).fadeIn("fast"); },
        function() { }
    );
    if (document.all) {
        $("#mainMenu li").hoverClass("mainMenuHover");
    }

    if ($('#mainMenu li a.active').length) {
        var activeImgSrc = $('#mainMenu li a.active img').attr('src');
        activeImgSrc = activeImgSrc.replace('.gif', '_active.gif');
        $('#mainMenu li a.active img').attr('src', activeImgSrc);
    };

    //tabs behavior
    $(".tabsHdrDiv div").click(function() {
        var id = $(this).attr("id").split('_')[1];

        //switch tabs headers
        $(".activeTab").children().attr("src", function() {
            this.src = this.src.replace("_on", "_off");
            this.src = this.src.replace("_hover", "_off");
        });

        $(".tabsHdrDiv div").removeClass();
        $(this).children().attr("src", function() {
            this.src = this.src.replace("_off", "_on");
            this.src = this.src.replace("_hover", "_on");
        });

        $(this).addClass("activeTab");

        //show/hide tabs content
        $(".tabsContentDiv > div").hide();
        $(".tabsContentDiv div#tab_" + id + "_content").show();
    });

    $(".tabsHdrDiv div img").hover(function() {
        if (!$(this).parent().hasClass("activeTab")) {
            this.src = this.src.replace("_off", "_hover");
        }
    }, function() {
        if (!$(this).parent().hasClass("activeTab")) {
            this.src = this.src.replace("_hover", "_off");
        }
    });

    //Brochures Confirmations Show/Hide	
    $('a.viewLess').hide();
    $("a.viewAll").click(function() {
        $('a.viewLess').show();
        $('a.viewAll').hide();
        $('.selectedBrochuresListing').addClass('expandDiv');
    });
    $("a.viewLess").click(function() {
        $('a.viewLess').hide();
        $('a.viewAll').show();
        $('.selectedBrochuresListing').removeClass('expandDiv');
    });

    $('.brochureBlock').each(function() {
        if ($(this).children('img').length) {
            $(this).addClass('withImage');
        } else {
            $(this).children('.details').css('width', '300px');
        }
    });

    $('.travelIdeaBlock .left').each(function() {
        if ($(this).children('img').length) {
        } else {
            $(this).css('display', 'none');
            $(this).siblings('.right').css('width', '605px').css('float', 'none').css('padding-left', '0');
        }
    });

    // Deals Pod Show/Hide
    $('#dealSearchForm').hide();
    $("#dealsFindSearch").click(function() {
        $('#dealSearchForm').toggle();
        $('#dealDetail').toggleClass('hideElement');
    });

    //set equal height to left and right
    var leftH = $(".tabContentLeft").height();
    var rightH = $(".tabContentRight").height();
    if (rightH < leftH) {
        //    $(".tabContentRight").css("height", leftH + "px");
    }

    $(".resultCategoryBlock:first, .myNYCategoryBlock").css("display", "block");
    $(".siteMapDiv .resultCategoryHdr").removeClass("resultCategoryHdrClick");

    //initial set    
    var selectClass = $("select.styled");
    var leftCat = $(".tabContentLeft .resultCategoryHdr");
    var rightCat = $(".tabContentRight .resultCategoryHdr");
    var typeClass = $(".refinerLinks div.refinerLink");
    var plusImgLeft = $(".tabContentLeft img.plusMinusBtn");
    var plusImgRight = $(".tabContentRight img.plusMinusBtn");

    $(".orderBrochure .resultItemsBlock:first").css("display", "block");
    $(".siteMapDiv .resultItemsBlock").css("display", "none");

    $(leftCat).mouseup(function() {

        var par = $(this).parent();
        var list = $(par).children(".tabContentLeft .resultItemsBlock");
        var plusDiv = $(this).children().children("img.plusMinusBtn");
        $(leftCat).removeClass("resultCategoryHdrHover");
        $(leftCat).removeClass("resultCategoryHdrClick");
        $(this).addClass("resultCategoryHdrClick");
        $(plusDiv).attr("src", $(plusDiv).attr("src").replace("_on.gif", ".gif"));

        if ($(list).css("display") == "none") {
            $(".tabContentLeft .resultItemsBlock").css("display", "none");
            $(".tabContentLeft img.plusMinusBtn").attr("src", $(".tabContentLeft img.plusMinusBtn").attr("src").replace("_minus", "_plus"));
            $(".tabContentLeft img.plusMinusBtn").attr("alt", $(".tabContentLeft img.plusMinusBtn").attr("alt").replace("Collapse", "Expand"));
            var ListStatus = $(list).css("display", "block");
            $(plusDiv).attr("src", $(plusDiv).attr("src").replace("_plus", "_minus"));
            $(plusDiv).attr("alt", $(plusDiv).attr("alt").replace("_Expand", "_Collapse"));
        } else if ($(list).css("display") == "block") {
            $(list).css("display", "none");
            $(".tabContentLeft .resultItemsBlock").css("display", "none");
            $(plusDiv).attr("src", $("img.plusMinusBtn").attr("src").replace("_minus", "_plus"));
            $(plusDiv).attr("alt", $("img.plusMinusBtn").attr("alt").replace("Expand", "Collapse"));
            $(leftCat).removeClass("resultCategoryHdrClick");
        }
        setParentHeight($('.active').parent().siblings('.tabContent'));
        $(plusDiv).attr("src", $(plusDiv).attr("src").replace("_on.gif", ".gif"));
    });

    $(rightCat).click(function() {
        var par = $(this).parent();
        var list = $(par).children(".tabContentRight .resultItemsBlock");
        var plusDiv = $(this).children().children("img.plusMinusBtn");
        var clickDiv = $(par).children(".tabContentRight .resultCategoryHdr");

        $(rightCat).removeClass("resultCategoryHdrHover");
        $(rightCat).removeClass("resultCategoryHdrClick");

        if ($(list).css("display") == "none") {
            $(".tabContentRight .resultItemsBlock").css("display", "none");
            $("img.plusMinusBtn").attr("src", $("img.plusMinusBtn").attr("src").replace("_minus", "_plus"));
            $("img.plusMinusBtn").attr("alt", $("img.plusMinusBtn").attr("alt").replace("Expand", "Collapse"));
            var ListStatus = $(list).css("display", "block");
            if ($(plusDiv).length != 0) {
                $(plusDiv).attr("src", $(plusDiv).attr("src").replace("_plus", "_minus"));
                $(plusDiv).attr("alt", $(plusDiv).attr("alt").replace("_Expand", "_Collapse"));
            }
            $(this).addClass("resultCategoryHdrClick");
            $(clickDiv).addClass("resultCategoryHdrClick");
            $(clickDiv).children('h3').addClass("selectedCat");
        } else if ($(list).css("display") == "block") {
            var ListStatus = $(list).css("display", "block");
            $(".tabContentRight .resultItemsBlock").css("display", "none");
            $(".tabContentRight img.plusMinusBtn").attr("src", $("img.plusMinusBtn").attr("src").replace("_minus", "_plus"));
            $(".tabContentRight img.plusMinusBtn").attr("alt", $("img.plusMinusBtn").attr("alt").replace("Expand", "Collapse"));
            $(this).removeClass("resultCategoryHdrClick");
            $(clickDiv).children('h3').removeClass("selectedCat");

        }
        setParentHeight($('.active').parent().siblings('.tabContent'));
    });

    //initial set    
    var myRightCat = $(".myNYCategoryBlock .resultCategoryHdr");
    var plusImg = $(".myNYCategoryBlock img.plusMinusBtn");
    $("#contentmain_0_ctrlUserDetail_userItems .resultCategoryBlock .resultItemsBlock").css("display", "none");
    $("#contentmain_0_ctrlUserDetail_userItems .resultCategoryBlock .resultItemsBlock:first").css("display", "block");
    $("#userItems .resultCategoryBlock .resultItemsBlock").css("display", "none");
    $("#userItems .resultCategoryBlock .resultItemsBlock:first").css("display", "block");
    $(".orderBrochure .resultCategoryBlock .resultItemsBlock").css("display", "none");
    $(".orderBrochure .resultCategoryBlock .resultItemsBlock:first").css("display", "block");
    myRightCat.each(function() {
        $(this).click(function() {
            $(this).addClass('activeItem');
            $(this).parent('.myNYCategoryBlock').siblings().children('.resultCategoryHdr').not(this).removeClass('activeItem');
        });
    });

    //for MY-NY
    $('.myTrip .itemRow .right').each(function() {
        if (($(this).children('img').length) || ($(this).children('itemInformation').children('img').length)) {
            $(this).addClass('withImage');
        }
    });

    $('.myTrip .itemRow .right .itemInformation').each(function() {
        if ($(this).children('img').length) {
            $(this).addClass('withImage');
        }
    });

    //Char limit
    $(function() {
        var limit = 500;
        $('textarea[id$=description]').keyup(function() {
            var len = $(this).val().length;
            if (len > limit) {
                this.value = this.value.substring(0, limit);
            }
            $('#charleft').text(limit - len + " characters left");
        });
    });

    $(myRightCat).mouseup(function() {
        var par = $(this).parent();
        var list = $(par).children(".resultItemsBlock");
        var plusDiv = $(this).children().children("img.plusMinusBtn");
        $(myRightCat).removeClass("resultCategoryHdrHover");
        $(myRightCat).removeClass("resultCategoryHdrClick");
        $(plusDiv).attr("src", $(plusDiv).attr("src").replace("_on.gif", ".gif"));
        if ($(list).css("display") == "none") {
            $(".resultItemsBlock").css("display", "none");
            $(".resultCategoryHdr img.plusMinusBtn").attr("src", $(".resultCategoryHdr img.plusMinusBtn").attr("src").replace("_minus", "_plus"));
            $(".resultCategoryHdr img.plusMinusBtn").attr("alt", $(".resultCategoryHdr img.plusMinusBtn").attr("alt").replace("Collapse", "Expand"));
            var ListStatus = $(list).css("display", "block");
            $(plusDiv).attr("src", $(plusDiv).attr("src").replace("_plus", "_minus"));
            $(plusDiv).attr("alt", $(plusDiv).attr("alt").replace("_Expand", "_Collapse"));
        } else if ($(list).css("display") == "block") {
            $(list).css("display", "none");
            $(".resultItemsBlock").css("display", "none");
            $(plusDiv).attr("src", $("img.plusMinusBtn").attr("src").replace("_plus", "_minus"));
            $(plusDiv).attr("src", $("img.plusMinusBtn").attr("src").replace("_minus", "_plus"));
            $(plusDiv).attr("alt", $("img.plusMinusBtn").attr("alt").replace("Expand", "Collapse"));
        }
        setParentHeight($('.active').parent().siblings('.tabContent'));
    });

    //Site Map
    var sitemap = $(".siteMapDiv .resultCategoryHdr");
    var plusImgSitemap = $(".siteMapDiv img.plusMinusBtn");

    $(sitemap).mouseup(function() {
        var par = $(this).parent();
        var list = $(par).children(".siteMapDiv .resultItemsBlock");
        var plusDiv = $(this).children().children("img.plusMinusBtn");

        if ($(list).css("display") == "none") {
            var ListStatus = $(list).css("display", "block");
            $(plusDiv).attr("src", $(plusDiv).attr("src").replace("_plus", "_minus"));
            $(plusDiv).attr("alt", $(plusDiv).attr("alt").replace("_Expand", "_Collapse"));
        } else if ($(list).css("display") == "block") {
            $(list).css("display", "none");
            $(plusDiv).attr("src", $("img.plusMinusBtn").attr("src").replace("_minus", "_plus"));
            $(plusDiv).attr("alt", $("img.plusMinusBtn").attr("alt").replace("Expand", "Collapse"));
        }
    });

    /*----------- Hovers for result category listings ---------- */
    $(leftCat).each(function() {
        $(this).hover(function() {
            $(this).addClass("resultCategoryHdrHover");
        }, function() {
            $(this).removeClass("resultCategoryHdrHover");
        });
    });

    $(rightCat).each(function() {
        $(this).hover(function() {
            $(this).addClass("resultCategoryHdrHover");
        }, function() {
            $(this).removeClass("resultCategoryHdrHover");
        });
    });

    $(myRightCat).each(function() {
        $(this).hover(function() {
            $(this).addClass("resultCategoryHdrHover");
        }, function() {
            $(this).removeClass("resultCategoryHdrHover");
        });
    });

    $('.itemInfo').each(function() {
        $(this).hover(function() {
            $(this).children('td').addClass("resultCategoryHdrHover");
        }, function() {
            $(this).children('td').removeClass("resultCategoryHdrHover");
        });
    });

    $(typeClass).each(function() {
        $(this).hover(function() {
            $(this).addClass("refinerLinkHover");
        }, function() {
            $(this).removeClass("refinerLinkHover");
        });
    });

    //plus img hovers
    $(plusImgLeft).each(function() {
        $(this).hover(function() {
            this.src = this.src.replace(".gif", "_on.gif");
        }, function() {
            this.src = this.src.replace("_on.gif", ".gif");
        });
    });

    $(plusImgRight.not(':first')).each(function() {
        $(this).hover(function() {
            this.src = this.src.replace(".gif", "_on.gif");
        }, function() {
            this.src = this.src.replace("_on.gif", ".gif");
        });
    });

    $(plusImg).each(function() {
        $(this).hover(function() {
            this.src = this.src.replace(".gif", "_on.gif");
        }, function() {
            this.src = this.src.replace("_on.gif", ".gif");
        });
    });

    $(plusImgSitemap).each(function() {
        $(this).hover(function() {
            this.src = this.src.replace(".gif", "_on.gif");
        }, function() {
            this.src = this.src.replace("_on.gif", ".gif");
        });
    });

    /* Featured Section Functionality, Matt Thomas
    ------------------------------------------------------*/
    $('#featuredNav li a').click(function() {
        $('#featuredNav li a').removeClass('active');
        $(this).addClass('active');
        var whichContent = $(this).attr('rel');
        if ($('#' + whichContent).hasClass('active')) {
            return;
        } else {
            $('.featuredContent.active').removeClass('active');
            $('#' + whichContent).addClass('active');
        }
    });

    /* Begin Featured Active Rotation
    ------------------------------------------------------ */
    (function() {
        var aFeatured = [];
        var nCurr = -1;
        var t;
        var speed = 6000;
        var started = false;

        $('#featuredNav li').each(function() {
            aFeatured.push($(this).attr('id'));
        });

        function initRotate() {
            if (!started) {
                started = true;
                rotateFeatured();
            }
        }

        function rotateFeatured() {
            if (nCurr < aFeatured.length) {
                nCurr++;
            }
            if ($('.bubble').length > 0 && nCurr == aFeatured.length) {
                started = false;
                clearTimeout(t);
                return;
            }
            if (nCurr == aFeatured.length) {
                nCurr = 0;
                started = false;
                clearTimeout(t);
            }
            $('#featuredNav li a').removeClass('active');
            $('#' + aFeatured[nCurr]).children('a').addClass('active');
            var fContent = $('#' + aFeatured[nCurr]).children('a').attr('rel');
            $('.featuredContent').removeClass('active'); // add .fadeOut('slow')
            $('#' + fContent).addClass('active');  // add .fadeIn('slow')
            t = setTimeout(rotateFeatured, speed);
        }

        $('#featuredNav li a').click(function() {
            clearTimeout(t);
        });
        initRotate();
    })();


    /* New Tab Functionality
    ----------------------------------------------------------*/
    //applying style for first visible tab
    var hiddenFirstTab = $('a.firstTab').parent('.hiddenDiv');
    var sibChildren = hiddenFirstTab.siblings().children();
    sibChildren.addClass('tabLink');
    sibChildren.removeClass('firstTab');
    $('.tabLink:first').addClass('firstTab');

    $('.tabNav li a').click(function() {
        $('.tabNav li a').removeClass('active');
        $(this).addClass('active');
        var tabContent = $(this).attr('rel');

        if ($('#' + tabContent).hasClass('active')) {
            return;
        } else {
            $('.tabContent.active').removeClass('active');
            $('#' + tabContent).addClass('active');
        }
    });

    /* Cities and Towns
    ----------------------------------------------------------*/
    $('.alphabet a').click(function() {
        $('.alphabet a').each(function() {
            $(this).removeClass('active');
        });
        $(this).addClass('active');
    });

    //Register / Login boxes
    if ($('.zipStep1').val != '') {
        $('.zipStep3').val($('.zipStep1'));
    }

    //Date Picker Input
    $('.calendarInput').each(function() {
        if ($(this).val() == "") {
            $(this).css('background-image', 'url(/Images/datePickerDefault.jpg)');
        }
        $(this).focus(function() {
            $(this).css('background-image', 'none');
        }).blur(function() {
            if ($(this).val() == '') {
                $(this).css('background-image', 'url(/Images/datePickerDefault.jpg)');
            }
        }).change(function() {
            $(this).css('background-image', 'none');
        });
    });

    $(".formFindEventsHome .calendarInput").datePicker({
        clickInput: true,
        startDate: '01/01/2009',
        showYearNavigation: false
    }).click(function() {
        $('#dp-popup').css('margin-left', '140px');
    });

    $('#dealfinder .calendarInput').datePicker({
        clickInput: true,
        startDate: '01/01/2009',
        showYearNavigation: false
    }).click(function() {
        $('div#dp-popup').css('margin-left', '140px');
    });

    $('.nextBtn, input.submitBtn, .previousBtn, .loginBtn, .saveBtn, .changePassword, .cancelChange, input.orderNowBtn, input.findDeals').mouseover(function() {
        $(this).css('background-position', 'left bottom');
    }).mouseout(function() {
        $(this).css('background-position', 'left top');
    }).focus(function() {
        $(this).css('background-position', 'left bottom');
    }).blur(function() {
        $(this).css('background-position', 'left top');
    });

    $('input.logoutBtn, input.forgotBtn').mouseover(function() {
        $(this).css('background-color', '#fbd13e');
    }).mouseout(function() {
        $(this).css('background-color', 'transparent');
    }).focus(function() {
        $(this).css('background-color', '#fbd13e');
    }).blur(function() {
        $(this).css('background-color', 'transparent');
    });

    // Select All checkboxes functionality
    $('#selectAllOffers').click(function() {
        var checkedStatus = this.checked;
        $("input[name=offers]").each(function() {
            this.checked = checkedStatus;
        });
    });

    $('#selectAllTravelInterests').click(function() {
        var checkedStatus = this.checked;
        $("input.travelInterests").each(function() {
            this.checked = checkedStatus;
        });
    });
    $('#selectAllAreas').click(function() {
        var checkedStatus = this.checked;
        $("input.travelAreaOfInterest").each(function() {
            this.checked = checkedStatus;
        });
    });

    // Search Bar
    $('.ac_results').click(function() {
        searchDeviceOn();
    });

    $('#searchbar').hover(function() {
        searchDeviceOn();
    }, function() {
        if ($('.ac_results').css("display") == "block") {
            return;
        } else {
            searchDeviceOff();
        }
    });

    function searchDeviceOn() {
        $('#search_cursor').hide();
        $('#search_button').show();
        $('#search_button').animate(
            { opacity: "1" },
            500
        );

        $('#search_field').show();
        $('#search_field').stop();

        var w = parseInt($('#search_field').css("width"));

        if (w > 0)
            $("#search_field").css({})
        $('#search_field').animate(
            { paddingLeft: "0px",
                paddingRight: "0px"
            },
            {
                duration: 500,
                queue: false,
                complete: function() {
                    $(this).css({ paddingLeft: "0px", paddingRight: "0px", width: "200px" })
                }
            }
        );
    };

    function searchDeviceOff() {
        $('#search_button').animate(
            { opacity: "0" },
            500
        );
        $('#search_field').stop();
        var w = parseInt($('#search_field').css("width"));
        if (w > 0)
            $("#search_field").css({})

        $('#search_field').animate(
            { paddingLeft: "0px",
                paddingRight: "0px"
            },
            { duration: 500,
                queue: false,
                complete: function() {
                    $(this).hide()
                    $('#search_cursor').show();
                }
            }
        );
    };

    //Hover state for select, city input, date picker
    $("select.styled").each(function() {
        $(this).hover(function() {
            $(this).siblings("span.select").css('background-image', 'url(/Images/form-fancybox2-over.jpg)');
        }, function() {
            $(this).siblings("span.select").css('background-image', 'url(/Images/form-fancybox2.jpg)');
        }).focus(function() {
            $(this).siblings('span.select').css('outline', '1px dotted').css('background-image', 'url(/Images/form-fancybox2-over.jpg)');
        }).blur(function() {
            $(this).siblings('span.select').css('outline', 'none').css('background-image', 'url(/Images/form-fancybox2.jpg)');
        });
    });

    $('.calendarInput').each(function() {
        $(this).focus(function() {
            $(this).siblings('.dp-choose-date').css('background-image', 'url(/Images/bg_icon_calendar-over.gif)');
        }).blur(function() {
            $(this).siblings('.dp-choose-date').css('background-image', 'url(/Images/bg_icon_calendar.gif)');
        }).hover(function() {
            $(this).siblings(".dp-choose-date").css('background-image', 'url(/Images/bg_icon_calendar-over.gif)');
        }, function() {
            $(this).siblings(".dp-choose-date").css('background-image', 'url(/Images/bg_icon_calendar.gif)');
        });
    });

    $(".cityInput").each(function() {
        $(this).hover(function() {
            $(this).siblings(".arrowRight").css('background-image', 'url(/Images/arrows-right-over.jpg)');
        }, function() {
            $(this).siblings(".arrowRight").css('background-image', 'url(/Images/arrows-right.jpg)');
        }).focus(function() {
            $(this).siblings('.arrowRight').css('background-image', 'url(/Images/arrows-right-over.jpg)');
        }).blur(function() {
            $(this).siblings('.arrowRight').css('background-image', 'url(/Images/arrows-right.jpg)');
        });
    });

    $(".arrowRight").each(function() {
        $(this).hover(function() {
            $(this).css('background-image', 'url(/Images/arrows-right-over.jpg)');
        }, function() {
            $(this).css('background-image', 'url(/Images/arrows-right.jpg)');
        }).focus(function() {
            $(this).css('background-image', 'url(/Images/arrows-right-over.jpg)');
        }).blur(function() {
            $(this).css('background-image', 'url(/Images/arrows-right.jpg)');
        });
    });

    //Popular Destinations POD
    $(".popularCities li:last-child").css("background", "none");

    //Login form submit on enter key press on password field
    $(".passwordField, .emailField").bind("keydown", function(event) {
        if (event.keyCode == 13) {
            $('.loginSubmit').click();
            return false;
        } else {
            return true;
        }
    });

    //Registration form submit on enter key press on country drop down
    //    var lastField = $("select.styled").attr('ToolTip');
    //    $(lastField).bind("keydown", function(event) {
    //        if (event.keyCode == 13) {
    //            $('.submitBtn').click();
    //            return false;
    //        }
    //        else {
    //            return true;
    //        }
    //    });

    //Search form submit on enter key on search field
    $("#search_field, .ac_results").bind("keydown", function(event) {
        if (event.keyCode == 13) {
            $('#search_button').click();
            return false;
        } else {
            return true;
        }
    });

    //Contact Us form submit on enter key on required fields
    $(".enterEvent").bind("keydown", function(event) {
        if (event.keyCode == 13) {
            $('.contactBtnSubmit').click();
            return false;
        } else {
            return true;
        }
    });

    // SubPageTitle H2 Length
    $(".listingContainer .subPageTitle h1, .listingContainer .subPageTitle h2").each(function() {
        var H2width = $(this).width();
        if (isIE6()) {
            if (H2width >= 375) {
                $(this).css('width', '375px');
            }
        } else if (isIE7()) {
            if (H2width >= 380) {
                $(this).css('width', '380px');
            }
        } else {
            if (H2width >= 475) {
                $(this).css('width', '475px');
            }
        }
    });

    // popup window
    $('a.printBtn').click(function() {
        window.open("/MyTripPrint.aspx", "MyTripPrint", "width=820,height=600,resizable=yes,status=yes,toolbar=no,menubar=yes,scrollbars=yes");
        return false;
    });

    // Margin for text pages fomr first header and paragraphs on page
    $('.tabContentTxt h1:first').css('margin-top', '0');
    $('.tabContentTxt h2:first').css('margin-top', '0');
    $('.tabContentTxt h3:first').css('margin-top', '0');
    $('.tabContentTxt h4:first').css('margin-top', '0');
    $('.tabContentTxt h5:first').css('margin-top', '0');
    $('.tabContentTxt h6:first').css('margin-top', '0');
    $('.tabContentTxt p:first').css('margin-top', '0');

    //Flash intro on a MAC
    if ($.client.os == 'MAC') {
        $('.flashDiv').css('top', '-1px').css('left', '-1px');
    }


    // Adjusting columns for even height based on content and page
    var pathname = window.location.pathname;
    if (pathname == '/What-To-Do.aspx') {
        $('#gridContainer #adDiv').css('height', '389px');
        if (isIE6()) {
            $('#gridContainer #adDiv').css('height', '399px');
        }
    }
    if ((pathname == '/Where-To-Stay.aspx') || (pathname == '/Cities-And-Towns.aspx')) {
        if (isIE6()) {
            $('#gridContainer #adDiv').css('height', '299px');
        } else {
            $('#gridContainer #adDiv').css('height', '309px');
        }
    }
    if (pathname == '/Find-Deals.aspx') {
        $('#gridContainer .cont_8x8').css('height', '612px');
        $('#gridContainer #adDiv').css('height', '281px');
        if (isIE6()) {
            $('#gridContainer #adDiv').css('height', '291px');
        }
    }
    if (pathname == '/Plan-Your-Trip.aspx') {
        $('#gridContainer .cont_8x8').css('height', '612px');
        $('#gridContainer .cont_4x8').css('height', 'auto');
        $('#gridContainer #adDiv').css('height', '281px');
        if (isIE6()) {
            $('#gridContainer #adDiv').css('height', '291px');
        }
    }
});





(function() {//Put Global Info Here
    window.ilny = new function() {
        this.mainMenu = new function() {
            /*this.mmHoverColor = "#F2F0B8";*/
        }

    }
})();

function threeCols(src, type) {
    var origList = src;
    var leftList = document.createElement(type);
    var centerList = document.createElement(type);
    var rightList = document.createElement(type);
    var container = document.createElement('div');
    var items = origList.getElementsByTagName('LI');
    var itemsLength = items.length / 3;
    for (i = 0; i < itemsLength; i++) {
        leftList.appendChild(items[0]);
    }
    itemsLength = items.length / 2;
    for (i = 0; i < itemsLength; i++) {
        centerList.appendChild(items[0]);
    }
    itemsLength = items.length;
    for (i = 0; i < itemsLength; i++) {
        rightList.appendChild(items[0]);
    }
    container.appendChild(leftList);
    container.appendChild(centerList);
    container.appendChild(rightList);
    leftList.setAttribute('class', 'left');
    centerList.setAttribute('class', 'center');
    rightList.setAttribute('class', 'right');
    container.setAttribute('class', 'threecol');

    if (document.all) {
        leftList.setAttribute('className', 'left');
        centerList.setAttribute('className', 'center');
        rightList.setAttribute('className', 'right');
        container.setAttribute('className', 'threecol');
    }

    if (type == 'ol') {
        centerList.setAttribute('start', leftList.getElementsByTagName('LI').length + 1);
        rightList.setAttribute('start', centerList.getElementsByTagName('LI').length + 1);
    }
    origList.parentNode.replaceChild(container, origList);
}

function allThreeCols(whichclass, type) {
    var uls = document.getElementsByTagName(type);
    for (var i = 0; i < uls.length; i++) {
        if (uls[i].getAttribute('class') == whichclass || uls[i].getAttribute('className') == whichclass) {
            threeCols(uls[i], type.toLowerCase());
        }
    }
}

$.fn.hoverClass = function(c) {
    return this.each(function() {
        $(this).hover(
            function() { $(this).addClass(c); },
            function() { $(this).removeClass(c); }
        );
    });
};


// Function (plug-in) added to detect browsers to target
(function() {

    var BrowserDetect = {
        init: function() {
            this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
            this.version = this.searchVersion(navigator.userAgent)
				|| this.searchVersion(navigator.appVersion)
				|| "an unknown version";
            this.OS = this.searchString(this.dataOS) || "an unknown OS";
        },
        searchString: function(data) {
            for (var i = 0; i < data.length; i++) {
                var dataString = data[i].string;
                var dataProp = data[i].prop;
                this.versionSearchString = data[i].versionSearch || data[i].identity;
                if (dataString) {
                    if (dataString.indexOf(data[i].subString) != -1)
                        return data[i].identity;
                }
                else if (dataProp)
                    return data[i].identity;
            }
        },
        searchVersion: function(dataString) {
            var index = dataString.indexOf(this.versionSearchString);
            if (index == -1) return;
            return parseFloat(dataString.substring(index + this.versionSearchString.length + 1));
        },
        dataBrowser: [
			{
			    string: navigator.userAgent,
			    subString: "Chrome",
			    identity: "Chrome"
			},
			{ string: navigator.userAgent,
			    subString: "OmniWeb",
			    versionSearch: "OmniWeb/",
			    identity: "OmniWeb"
			},
			{
			    string: navigator.vendor,
			    subString: "Apple",
			    identity: "Safari",
			    versionSearch: "Version"
			},
			{
			    prop: window.opera,
			    identity: "Opera"
			},
			{
			    string: navigator.vendor,
			    subString: "iCab",
			    identity: "iCab"
			},
			{
			    string: navigator.vendor,
			    subString: "KDE",
			    identity: "Konqueror"
			},
			{
			    string: navigator.userAgent,
			    subString: "Firefox",
			    identity: "Firefox"
			},
			{
			    string: navigator.vendor,
			    subString: "Camino",
			    identity: "Camino"
			},
			{		// for newer Netscapes (6+)
			    string: navigator.userAgent,
			    subString: "Netscape",
			    identity: "Netscape"
			},
			{
			    string: navigator.userAgent,
			    subString: "MSIE",
			    identity: "Explorer",
			    versionSearch: "MSIE"
			},
			{
			    string: navigator.userAgent,
			    subString: "Gecko",
			    identity: "Mozilla",
			    versionSearch: "rv"
			},
			{ 		// for older Netscapes (4-)
			    string: navigator.userAgent,
			    subString: "Mozilla",
			    identity: "Netscape",
			    versionSearch: "Mozilla"
			}
		],
        dataOS: [
			{
			    string: navigator.platform,
			    subString: "Win",
			    identity: "Windows"
			},
			{
			    string: navigator.platform,
			    subString: "Mac",
			    identity: "Mac"
			},
			{
			    string: navigator.userAgent,
			    subString: "iPhone",
			    identity: "iPhone/iPod"
			},
			{
			    string: navigator.platform,
			    subString: "Linux",
			    identity: "Linux"
			}
		]

    };

    BrowserDetect.init();

    window.$.client = { os: BrowserDetect.OS, browser: BrowserDetect.browser };

})();

// Function (plug-in) added to force users to type numeric and forward slash for calendar inputs
(function(h) { var f = { pint: /[\d\/]/, "int": /[\d\-]/, pnum: /[\d\.]/, money: /[\d\.\s,]/, num: /[\d\-\.]/, hex: /[0-9a-f]/i, email: /[a-z0-9_\.\-@]/i, alpha: /[a-z_]/i, alphanum: /[a-z0-9_]/i }; var c = { TAB: 9, RETURN: 13, ESC: 27, BACKSPACE: 8, DELETE: 46 }; var a = { 63234: 37, 63235: 39, 63232: 38, 63233: 40, 63276: 33, 63277: 34, 63272: 46, 63273: 36, 63275: 35 }; var e = function(j) { var i = j.keyCode; i = h.browser.safari ? (a[i] || i) : i; return (i >= 33 && i <= 40) || i == c.RETURN || i == c.TAB || i == c.ESC }; var d = function(j) { var i = j.keyCode; var l = j.charCode; return i == 9 || i == 13 || (i == 40 && (!h.browser.opera || !j.shiftKey)) || i == 27 || i == 16 || i == 17 || (i >= 18 && i <= 20) || (h.browser.opera && !j.shiftKey && (i == 8 || (i >= 33 && i <= 35) || (i >= 36 && i <= 39) || (i >= 44 && i <= 45))) }; var b = function(j) { var i = j.keyCode || j.charCode; return h.browser.safari ? (a[i] || i) : i }; var g = function(i) { return i.charCode || i.keyCode || i.which }; h.fn.keyfilter = function(i) { return this.keypress(function(m) { if (m.ctrlKey || m.altKey) { return } var j = b(m); if (h.browser.mozilla && (e(m) || j == c.BACKSPACE || (j == c.DELETE && m.charCode == 0))) { return } var o = g(m), n = String.fromCharCode(o), l = true; if (!h.browser.mozilla && (d(m) || !n)) { return } if (h.isFunction(i)) { l = i.call(this, n) } else { l = i.test(n) } if (!l) { m.preventDefault() } }) }; h.extend(h.fn.keyfilter, { defaults: { masks: f }, version: 1.7 }); h(document).ready(function() { var i = h("input[class*=mask],textarea[class*=mask]"); for (var j in h.fn.keyfilter.defaults.masks) { i.filter(".mask-" + j).keyfilter(h.fn.keyfilter.defaults.masks[j]) } }) })(jQuery);

// Function (plug-in) added to determine url parameters on the front-end
jQuery.fn.extend({
    /**
    * Returns get parameters.
    *
    * If the desired param does not exist, null will be returned
    *
    * To get the document params:
    * @example value = $(document).getUrlParam("paramName");
    * 
    * To get the params of a html-attribut (uses src attribute)
    * @example value = $('#imgLink').getUrlParam("paramName");
    */
    getUrlParam: function(strParamName) {
        strParamName = escape(unescape(strParamName));
        var returnVal = new Array();
        var qString = null;

        if ($(this).attr("nodeName") == "#document") {
            //document-handler
            if (window.location.search.search(strParamName) > -1) {
                qString = window.location.search.substr(1, window.location.search.length).split("&");
            }
        } else if ($(this).attr("src") != "undefined") {
            var strHref = $(this).attr("src")
            if (strHref.indexOf("?") > -1) {
                var strQueryString = strHref.substr(strHref.indexOf("?") + 1);
                qString = strQueryString.split("&");
            }
        } else if ($(this).attr("href") != "undefined") {
            var strHref = $(this).attr("href")
            if (strHref.indexOf("?") > -1) {
                var strQueryString = strHref.substr(strHref.indexOf("?") + 1);
                qString = strQueryString.split("&");
            }
        } else {
            return null;
        }
        if (qString == null) return null;
        for (var i = 0; i < qString.length; i++) {
            if (escape(unescape(qString[i].split("=")[0])) == strParamName) {
                returnVal.push(qString[i].split("=")[1]);
            }
        }
        if (returnVal.length == 0) return null;
        else if (returnVal.length == 1) return returnVal[0];
        else return returnVal;
    }
});

//Jquery plugin to urlcode a url
$.extend({ URLEncode: function(c) {
    var o = ''; var x = 0; c = c.toString(); var r = /(^[a-zA-Z0-9_.]*)/;
    while (x < c.length) {
        var m = r.exec(c.substr(x));
        if (m != null && m.length > 1 && m[1] != '') {
            o += m[1]; x += m[1].length;
        } else {
            if (c[x] == ' ') o += '+'; else {
                var d = c.charCodeAt(x); var h = d.toString(16);
                o += '%' + (h.length < 2 ? '0' : '') + h.toUpperCase();
            } x++;
        } 
    } return o;
},
    URLDecode: function(s) {
        var o = s; var binVal, t; var r = /(%[^%]{2})/;
        while ((m = r.exec(o)) != null && m.length > 1 && m[1] != '') {
            b = parseInt(m[1].substr(1), 16);
            t = String.fromCharCode(b); o = o.replace(m[1], t);
        } return o;
    }
});
