﻿$(function() {
    $('#coda-slider-1').codaSlider({
        autoSlide: true,
        autoSlideInterval: 8000,
        autoSlideStopWhenClicked: true,
        dynamicArrows: false//,
        /*dynamicTabs: true*/
    });




    $("ul").each(function() {
        $(this).find("li:first").addClass("first");
        $(this).find("li:last").addClass("last");
    });

    /*********************************************
    * Get Element Background Position
    ***********************************************/
    jQuery.fn.BackgroundPosition = function() {
        var bgPosition = $(this).css('background-position');
        if (typeof (bgPosition) === 'undefined') return $(this).css('background-position-x') + ' ' + $(this).css('background-position-y');
        else return bgPosition;
    };

    //$('ul.nav li').each(function() {
    $('div.nav div.topMenuItem').each(function() {
        $(this).hover(function() {
            
            var mainSelector = $(this);
            var selecto = $('a.topLevel', mainSelector);
            var currentBgPos = $(selecto).BackgroundPosition();
            var getBgLeftPos = currentBgPos != null ? currentBgPos.split(' ')[1] : null;
            if (getBgLeftPos != null) {
                var getIntValue = getBgLeftPos.split('px')[0];
                var bgNewPos = getIntValue - (-10);
                if ($.browser.msie) {
                    $(selecto).css({ "visibility": "visible" });
                    $('div.subMenuBox', mainSelector).css({ "visibility": "visible" }); ;
                }
                $(selecto).css({ "background-position": "0 " + bgNewPos + "px", "height": "45px" });
                //$(mainSelector + ' div.subMenuBox').stop(true, true).show();
                //$(mainSelector + ' div.subMenuBox').show();
                $(mainSelector).children('.subMenuBox').show();
            }
        }, function() {
            
            var mainSelector = $(this);
            var selecto = $('a.topLevel', mainSelector);
            var currentBgPos = $(selecto).BackgroundPosition();
            var getBgLeftPos = currentBgPos != null ? currentBgPos.split(' ')[1] : null;
            if (getBgLeftPos != null) {
                var getIntValue = getBgLeftPos.split('px')[0];
                var bgNewPos = getIntValue - (+10);
                $(selecto).css({ "background-position": "0 " + bgNewPos + "px", "height": "35px" });
                //$(mainSelector +' div.subMenuBox').stop(true, true).hide();
                //$(mainSelector + ' div.subMenuBox').hide();
                $(mainSelector).children('.subMenuBox').hide();
            }
        });
    });
});

$(document).ready(function() {

//set main content and sidebar to the same height
$.fn.setAllToMaxHeight = function(){
return this.height( Math.max.apply(this, $.map( this , function(e){ return $(e).height() }) ) );
}
$('.heightMatch').setAllToMaxHeight()

//subtract cta height from main content height
var StickyWrapperHeight = $('.heightMatch').height() - $('.itinerary').height() - 50 + "px";

//stretch sticky_wrapper height to fill sidebar 
$('.sticky_wrapper').height(StickyWrapperHeight);

//call sticky plugin
$('.sticky').containedStickyScroll({
        duration: 300,
        floatTop: 20,
        closeTop: 3,
        closeRight: 14
    });
});
