﻿///**************************************************************************************************
/*
* 
* hoverIntent r6 // 2011.02.26 // jQuery 1.5.1+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* hoverIntent is currently available for use in all personal or commercial 
* projects under both MIT and GPL licenses. This means that you can choose 
* the license that best suits your project, and use it accordingly.
* 
* @author    Brian Cherne brian(at)cherne(dot)net
*/
(function($) {
    $.fn.hoverIntent = function(f, g) {
        // default configuration options
        var cfg = {
            sensitivity: 7,
            interval: 100,
            timeout: 0
        };
        // override configuration options with user supplied object
        cfg = $.extend(cfg, g ? { over: f, out: g} : f);

        // instantiate variables
        // cX, cY = current X and Y position of mouse, updated by mousemove event
        // pX, pY = previous X and Y position of mouse, set by mouseover and polling interval
        var cX, cY, pX, pY;

        // A private function for getting mouse position
        var track = function(ev) {
            cX = ev.pageX;
            cY = ev.pageY;
        };

        // A private function for comparing current and previous mouse position
        var compare = function(ev, ob) {
            ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
            // compare mouse positions to see if they've crossed the threshold
            if ((Math.abs(pX - cX) + Math.abs(pY - cY)) < cfg.sensitivity) {
                $(ob).unbind("mousemove", track);
                // set hoverIntent state to true (so mouseOut can be called)
                ob.hoverIntent_s = 1;
                return cfg.over.apply(ob, [ev]);
            } else {
                // set previous coordinates for next time
                pX = cX; pY = cY;
                // use self-calling timeout, guarantees intervals are spaced out properly (avoids JavaScript timer bugs)
                ob.hoverIntent_t = setTimeout(function() { compare(ev, ob); }, cfg.interval);
            }
        };

        // A private function for delaying the mouseOut function
        var delay = function(ev, ob) {
            ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t);
            ob.hoverIntent_s = 0;
            return cfg.out.apply(ob, [ev]);
        };

        // A private function for handling mouse 'hovering'
        var handleHover = function(e) {
            // copy objects to be passed into t (required for event object to be passed in IE)
            var ev = jQuery.extend({}, e);
            var ob = this;

            // cancel hoverIntent timer if it exists
            if (ob.hoverIntent_t) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); }

            // if e.type == "mouseenter"
            if (e.type == "mouseenter") {
                // set "previous" X and Y position based on initial entry point
                pX = ev.pageX; pY = ev.pageY;
                // update "current" X and Y position based on mousemove
                $(ob).bind("mousemove", track);
                // start polling interval (self-calling timeout) to compare mouse coordinates over time
                if (ob.hoverIntent_s != 1) { ob.hoverIntent_t = setTimeout(function() { compare(ev, ob); }, cfg.interval); }

                // else e.type == "mouseleave"
            } else {
                // unbind expensive mousemove event
                $(ob).unbind("mousemove", track);
                // if hoverIntent state is true, then call the mouseOut function after the specified delay
                if (ob.hoverIntent_s == 1) { ob.hoverIntent_t = setTimeout(function() { delay(ev, ob); }, cfg.timeout); }
            }
        };

        // bind the function to the two event listeners
        return this.bind('mouseenter', handleHover).bind('mouseleave', handleHover);
    };
})(jQuery);
//********************************************************************************************
//********************************************************************************************
//Reservation Timer
var ResCalClickTimer;

function DocumentReadyHeader() {
    $(".tc-header-reservations-promos").hover(function() {
        $(this).animate({ "width": "290px", "margin-left": "10px", "margin-right": "10px" }, 100);
        _gaq.push(['_trackEvent', 'TC Reservation Promos', 'Hovered']);
    }, function() {
        $(this).animate({ "width": "270px", "margin-left": "20px", "margin-right": "20px" });
    });

    $("#tc-header-entertainment").hoverIntent({
        over: GrowElement,
        timeout: 350,
        out: ShrinkElement
    });

    $("#tc-header-reservations").hoverIntent({
        over: GrowElementRes,
        timeout: 350,
        out: ShrinkElementRes
    });

    $("#TCRewardsContainer").hoverIntent({
        over: RewardsOpen,
        timeout: 500,
        out: RewardsClose
    });

    $("#tc-sidenav-tab").hoverIntent({
        over: GrowSideNav,
        timeout: 500,
        out: ShrinkSideNav
    });

    $("#GamingNavItem").hoverIntent({
        over: GrowGaming,
        timeout: 500,
        out: ShrinkGaming
    });

    $("#RewardNavItem").hoverIntent({
        over: GrowRewards,
        timeout: 500,
        out: ShrinkRewards
    });

    $("#EntertainNavItem").hoverIntent({
        over: GrowEntertain,
        timeout: 500,
        out: ShrinkEntertain
    });

    $("#DiningNavItem").hoverIntent({
        over: GrowDining,
        timeout: 500,
        out: ShrinkDining
    });

}
//***************************
//*********************************************************
//*********** Navigation **********************************
//GAMING
function GrowGaming() {
    $("#GamingSubMenu").slideDown("fast");
}

function ShrinkGaming() {
    $("#GamingSubMenu").slideUp("fast");
}

//REWARDS
function GrowRewards() {
    $("#RewardsSubMenu").slideDown("fast");
}

function ShrinkRewards() {
    $("#RewardsSubMenu").slideUp("fast");
}

//ENTERTAINMENT
function GrowEntertain() {
    $("#EntertainSubMenu").slideDown("fast");
}

function ShrinkEntertain() {
    $("#EntertainSubMenu").slideUp("fast");
}

//DINING

function GrowDining() {
    $("#DiningSubMenu").slideDown("fast");
}

function ShrinkDining() {
    $("#DiningSubMenu").slideUp("fast");
}

//RESORT


//*********************************************************
//*********************************************************
//*********************************************************
function GrowSideNav() {
    //_gaq.push(['_trackEvent', 'TC Quick Links', 'Hovered']);
    $("#OuterSlide").animate({ "width": "330px" }, 200);
    $("#tc-sidenav").css("display", "block");
    //$("#tc-sidenav").css("margin-right", "0px");
}

function ShrinkSideNav() {
    $("#OuterSlide").animate({ "width": "35px" }, 200);
    $("#tc-sidenav").css("display", "none");
    //$("#tc-sidenav").css("margin-right", "35px");
}


//*********************************************************

//***************************
//Entertainment Popup hover code
//mousein
function GrowElement() {
    $(this).css("overflow", "visible");
    $(this).animate({ "top": "10px", "height": "369px" }, 330);
}
//Entertainment popup
//mouseout
function ShrinkElement() {
    $(this).css("overflow", "hidden");
    $(this).animate({ "top": "83px", "height": "30px" }, 330);

}
//Reservation popup
//mousein
function GrowElementRes() {
    $("#tc-header-reservations").animate({ "top": "10px", "height": "369px" }, 330);
}
//mouseout
function ShrinkElementRes() {
    if ($("#ui-datepicker-div").css("display") == "none") {
        $("#tc-header-reservations").animate({ "top": "83px", "height": "30px" }, 330);
    }
    else {
        ResCalClickTimer = setTimeout("ShrinkElementRes();", 1000);
    }
}

//Pick a date from javascript cal on reservation pop-up
function StopClose() {
    //alert("CLEARING");
    clearTimeout(ResCalClickTimer);

    setTimeout("CheckMouse();", 750);
}

function CheckMouse() {
    if ($("#tc-header-reservations").ismouseover()) {

    }
    else {
        ShrinkElementRes();
    }

}


//Rewards club hover
//Datetime appeneded to the end of the url of the gifs to make 
//the browser think it is a new image and not use the cached element
var d = new Date();
//Mousein
function RewardsOpen() {
    //_gaq.push(['_trackEvent', 'TC Rewards', 'Hovered']);
    d = new Date();
    $("#TCRewardsContainer").animate({ "width": "150px", "height": "290px" }, 500).delay(650);
    $("#RewardsBackground").animate({ "width": "150px", "height": "290px" }, 500).delay(650);
    $("#RewardsInitial").fadeOut(10);
    $("#PagePeelD").attr("src", "/media/header/PagePeel_Down_Narrow.gif?" + d.getTime());
    $("#RewardsPeel").fadeIn(20);
    $("#RewardLinkContainer").delay(1200).fadeIn(200)
    $("#tc-rewards-close").fadeIn(20);
}
//mouseout
function RewardsClose() {
    d = new Date();
    $("#TCRewardsContainer").delay(1000).animate({ "width": "100px", "height": "100px" }, 100);
    $("#RewardsBackground").delay(1000).animate({ "width": "100px", "height": "100px" }, 100);
    $("#RewardsPeel").fadeOut(10);
    $("#PagePeelU").attr("src", "/media/header/PagePeel_Up_Narrow.gif?" + d.getTime());
    $("#RewardsReturn").fadeIn(10).delay(1800).fadeOut(10);
    $("#RewardLinkContainer").fadeOut(200);
    $("#RewardsInitial").delay(1800).fadeIn(10);
    $("#tc-rewards-close").fadeOut(20);
}


//****************** landing clicks
function gamingLC() {
    window.location.href = "/entertainment/shows/";
};

function rewardsLC() {
    window.location.href = "/rewards-club/sign-up/";
};

function entertainLC() {
    window.location.href = "/entertainment/shows/";
};

function diningLC() {
    window.location.href = "/dining/tulalip-bay/";
};

function resortLC() {
    window.open("http://www.tulalipresort.com/specials/index.aspx");
};



//TESTING ismouseover

(function($) {
    jQuery.mlp = { x: 0, y: 0 }; // Mouse Last Position
    $(document).mousemove(function(e) {
        jQuery.mlp = { x: e.pageX, y: e.pageY }
    });
    function notNans(value) {
        if (isNaN(value)) {
            return 0;
        } else {
            return value
        }
    }
    $.fn.ismouseover = function(overThis) {
        var result;
        this.eq(0).each(function() {
            var offSet = $(this).offset();
            var w = Number($(this).width())
            + notNans(Number($(this).css("padding-left").replace("px", "")))
            + notNans(Number($(this).css("padding-right").replace("px", "")))
            + notNans(Number($(this).css("border-right-width").replace("px", "")))
            + notNans(Number($(this).css("border-left-width").replace("px", "")));
            var h = Number($(this).height())
            + notNans(Number($(this).css("padding-top").replace("px", "")))
            + notNans(Number($(this).css("padding-bottom").replace("px", "")))
            + notNans(Number($(this).css("border-top-width").replace("px", "")))
            + notNans(Number($(this).css("border-bottom-width").replace("px", "")));
            if (offSet.left < jQuery.mlp.x && offSet.left + w > jQuery.mlp.x
             && offSet.top < jQuery.mlp.y && offSet.top + h > jQuery.mlp.y) {
                result = true;
            } else {
                result = false;
            }
        });
        return result;
    };
})(jQuery); 
