// JavaScript Document



/* Global Variables

***********************************************************************/

var menuYPos = 0;

var menuAnimating = false;



var menu;

var nav;

var breadcrumbs;

var menuButton;

var menuButtonHover;

var menuButtonArrow;

var menuLogo;

var menuhovers;

var capaignNavHover;

var hotspotHovers;

var styleFitListingHovers;

var homeHero;

var listingContent;

var footerExtraHeight;

var tileSingle;

var tileDouble;

var tileFacebook;



/**********************************************************************/

function setCookie(c_name, value, exdays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + exdays);
    var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
    document.cookie = c_name + "=" + c_value;
}

function getCookie(c_name) {
    var i, x, y, ARRcookies = document.cookie.split(";");
    for (i = 0; i < ARRcookies.length; i++) {
        x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
        y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
        x = x.replace(/^\s+|\s+$/g, "");
        if (x == c_name) {
            return unescape(y);
        }
    }
}


/* Document Ready - items moved from window.load becuase of client issue

***********************************************************************/

$(document).ready(function () {

    var $signup = $('#ljSignUp');
    $signup.delegate('a', 'mouseenter mouseleave', function (e) {

        var _top = 32,
            _opacity = 1;

        if (e.type == 'mouseleave') {
            _top = 52;
            _opacity = 0;
        }

        $(this).siblings('img').animate({ top: _top, opacity: _opacity }, { duration: 200, queue: false, easing: 'easeOutQuad' });
    });

    //Check for first time users
    var leeuser = getCookie('leeNewUser');
    if (leeuser == null || leeuser == '' || leeuser == 'undefined') {
        $signup.find('img').animate({ top: 32, opacity: 1 }, { duration: 200, queue: false, easing: 'easeOutQuad', complete: function () {
            $(this).animate({ top: 32 }, 4800, function () { //Fake delay
                $(this).animate({ top: 52, opacity: 0 }, { duration: 200, queue: false, easing: 'easeOutQuad' });
            });
        }
        });

        setCookie('leeNewUser', 'true', 365);
    }

    // Blog links
    $(".blogReadMore").each(function () {
        // Show the link if there is a teaser ........
        var parentObj = $(this).parent("div");
        var blogTeaser = parentObj.children("div.blogTeaser:first");
        var blogContent = parentObj.children("div.blogContent:first");
        if (blogTeaser.html() != "") {
            $(this).show();
            blogTeaser.show();
            blogContent.hide();
        } else {
            blogTeaser.hide();
            blogContent.show();
        }
    });

    $(".blogReadMore").click(function () {
        var parentObj = $(this).parent("div");
        var blogContent = parentObj.children("div.blogContent:first");
        if (blogContent.is(":visible")) {
            blogContent.slideUp("slow");
            $(this).text("READ MORE");
        } else {
            blogContent.slideDown("slow");
            $(this).text("READ LESS");
        }
    });

    // Fix for Cufon font on IE7 - MAJOR HACK FOR CUFON !!!
    if ($.browser.msie && parseInt($.browser.version, 10) === 7) {
        //find the elements to change ....
        var cufonCampaignLines = $("#campaignNav h1 cufoncanvas");
        var offset = 0;
        cufonCampaignLines.each(function () {
            $(this).css('top', '-' + offset + 'px');
            offset = offset + 25;
        });
        var cufonHomeLines = $("#homeNav h1 cufoncanvas");
        var offset = 0;
        cufonHomeLines.each(function () {
            $(this).css('top', '-' + offset + 'px');
            offset = offset + 25;
        });
    }

    // Lat menu option should always be "GML FOR LEE" grab it and set to open in new window
    $("#breadcrumb li:last a").attr('target', '_blank');


});

/* Document Load

***********************************************************************/

$(window).load(function () {



    /* Set Global Variables

    ***********************************************************************/

    menu = $("#menu");

    nav = $("#nav");

    breadcrumbs = $("#breadcrumb .crumb");

    menuButton = $(".menuButton");

    menuButtonHover = $('#menu .menuButton a');

    menuButtonArrow = $(".menuButton .arrowIcon");

    menuLogo = $("#menu #logo");

    menuhovers = $('#menu a');

    capaignNavHover = $('#campaignNav a');

    hotspotHovers = $('.hotspot');

    styleFitListingHovers = $('#stylefitListing a');

    homeHero = $('#home .hero:first');

    listingContent = $('#listings .content');

    footerExtraHeight = $('.extraHeight');

    tileSingle = $('.tileItemSingle a');

    tileDouble = $('.tileItemDouble a');

    tileFacebook = $('.facebooktileItem');

    /**********************************************************************/

    //Initial Resize Check

    if ($(this).width() <= 1370) {

        homeHero.css('margin-right', '900px');

        listingContent.css('width', '576px');

    }

    else {

        homeHero.css('margin-right', 0);

        listingContent.css('width', '768px');

    }



    //Footer extra height first check

    var extraHeight = $(window).height() - ($('#footer').position().top + $('#footer').innerHeight());



    footerExtraHeight.css({ 'height': extraHeight + 'px' });





    // a href tag handler

    nav.click(function (e) {

        var tgt = $(e.target);

        var aTag = tgt.parents('a');



        if (aTag.length) {

            if (aTag.attr('href') == '#') {

                $('li ul').css({ "display": "none" });

                aTag.parents('li').children('ul').show();

                return false;

            }

        }

    });







    // Menu Arrow hover

    $('#breadcrumb a').hover(function () {

        $(this).parent().find('.arrowIcon').css('background-position', '-21px 0');

    },

	function () {

	    if (!$(this).parent().parent().hasClass('on')) {

	        $(this).parent().find('.arrowIcon').css('background-position', '0 0');

	    }

	});



    // Menu Button Arrow hover

    //	$('#breadcrumb .menuButton a').hover(function () {

    //        $(this).parent().find('.arrowIcon').css('background-position', '-21px ' + menuYPos);

    //    },

    //	function () {

    //		$(this).parent().find('.arrowIcon').css('background-position', '0 ' + menuYPos);

    //	});





    // Campaign Nav hover

    $('#campaignNav a').hover(function () {

        $(this).parent().find('.arrowIcon').css('background-position', '-21px 0');

    },

	function () {

	    $(this).parent().find('.arrowIcon').css('background-position', '0 0');

	});



    // Home Nav hover

    //    $('#homeNav a').hover(function () {

    //        $(this).parent().find('.arrowIcon').css('background-position', '-21px 0');

    //    },

    //	function () {

    //	    $(this).parent().find('.arrowIcon').css('background-position', '0 0');

    //	});



    // Hotspot hover

    $('.hotspot').hover(function () {

        //$(this).find('.plusIcon').css( {'opacity' : '0',  'display' : 'block'}).animate({'opacity' : '1'}, {duration:150, easing:easingMethod });

        $(this).children('.plusIcon').show();

    },

	function () {

	    //$(this).find('.plusIcon').css({'display' : 'none'});

	    $(this).children('.plusIcon').hide();

	});



    // Stylebook / Fitguide Listing Nav Hover

    styleFitListingHovers.hover(function () {

        $(this).parent().find('.arrowIcon').css('background-position', '-21px 0');

    },

	function () {

	    $(this).parent().find('.arrowIcon').css('background-position', '0 0');

	});


    // Tile item rollovers

    tileSingle.hover(function () {

        $(this).children('.tileInfo').stop().animate({ 'height': 100 }, { duration: 300, easing: easingMethod });

        $(this).children('.tileOverlay').css({ 'width': $(this).width() + 'px', 'height': $(this).height() + 'px' });

        $(this).children('.tileOverlay').fadeIn(200);

    },

	function () {

	    $(this).children('.tileInfo').stop().animate({ 'height': 83 }, { duration: 300, easing: easingMethod });



	    $(this).children('.tileOverlay').css({ 'filter': 'alpha(opacity=50)' });

	    $(this).children('.tileOverlay').fadeOut(100);

	});



    tileDouble.hover(function () {

        $(this).children('.tileInfo').stop().animate({ 'height': 100 }, { duration: 200, easing: easingMethod });

        $(this).children('.tileOverlay').css({ 'width': $(this).width() + 'px', 'height': $(this).height() + 'px' });

        $(this).children('.tileOverlay').fadeIn(200);

    },

	function () {

	    $(this).children('.tileInfo').stop().animate({ 'height': 83 }, { duration: 100, easing: easingMethod });

	    $(this).children('.tileOverlay').css({ 'filter': 'alpha(opacity=50)' });

	    $(this).children('.tileOverlay').fadeOut(100);

	});



    tileFacebook.hover(function () {

        $(this).children('.tileInfo').stop().animate({ 'height': 100 }, { duration: 200, easing: easingMethod });

    },

	function () {

	    $(this).children('.tileInfo').stop().animate({ 'height': 83 }, { duration: 100, easing: easingMethod });

	})


});



// Resize Handler

$(window).resize(function () {



    if ($(this).width() <= 1370) {

        homeHero.css('margin-right', '900px');

        listingContent.css('width', '576px');



    }

    else {

        homeHero.css('margin-right', 0);

        listingContent.css('width', '768px');

    }

});



/**********************************************************************/



/* Menu Functions

************************************************************************/

// Show Menu

function showMenu() {

	menuYPos = '-20px';

	

	breadcrumbs.animate({ 'opacity': 0 }, { duration: 300, easing: easingMethod, complete: function () {



	    breadcrumbs.css('display', 'none');





	    menuButtonArrow.css("backgroundPosition", "0 -20px");

	    menu.animate({ 'height': 283 }, { duration: 300, easing: easingMethod, complete: function () {

	        nav.show();

	        

            setTimeout(function () { nav.animate({ 'opacity': 1 }, { duration: 250, easing: easingMethod, complete: function(){

				

				

				 menuAnimating = false; 

				 $('#overlay').bind("click", function(e) {

					if($(e.target).attr("id") == "overlay"){

						hideMenuOverlay();

						 menu.data('open', false);

					}

				})

				 

				 } }); }, 100);



        

        } 

	    });

	  



	} 

	});

	

}



// Hide Menu

function hideMenu() {

	menuYPos = 0

	

	menuButtonArrow.css("backgroundPosition" , "0 0");



	nav.animate({ 'opacity': 0 }, { duration: 250, easing: easingMethod, complete: function () {





	    nav.hide();

	    menu.animate({ 'height': 95 }, { duration: 300, easing: easingMethod,

	        complete: function () {

	            breadcrumbs.css('display', 'block');

	            breadcrumbs.animate({ 'opacity': 1 }, { duration: 300, easing: easingMethod, complete: function(){ menuAnimating = false; } });



	        }





	    });

    

    } 

    

    

    

    });



	$('#overlay').unbind("click");

}



/***********************************************************************/



/* Menu Overlay

************************************************************************/

function showMenuOverlay() {

	var docWidth = $(document).width();

	var docHeight = $(document).height();

	var overlayHTML = '<div id="overlay" style="width:' + docWidth + 'px; height:' + docHeight + 'px"></div>';



	$('body').append(overlayHTML);

	

	

	

	$('#overlay').hide().css('opacity', 0.7).fadeIn(50, showMenu);

}



function hideMenuOverlay() {	

	$('#overlay').fadeOut(250, function() {

		

		$(this).hide().remove();

	});

	hideMenu();

}



/***********************************************************************/



/* Cufon

************************************************************************/

//Cufon.replace('h1, h2, h4, strong a, #footer, #slideshow .hotspot p, .standardForm h3, #zoomDisplay a, #interview .imagesCaption, #blog .comments .author, #blog .comments .date, .rollover p', { hover:true });

Cufon.replace('h2', { hover:true });

Cufon.replace('h4', { hover:true });

Cufon.replace('strong a', { hover:true });

Cufon.replace('#footer', { hover:true });

Cufon.replace('#slideshow .hotspot p', { hover:true });

Cufon.replace('.standardForm h3', { hover:true });

Cufon.replace('#zoomDisplay a', { hover:true });

Cufon.replace('#interview .imagesCaption', { hover:true });

Cufon.replace('#blog .comments .author', { hover:true });

Cufon.replace('#blog .comments .date', { hover:true });

Cufon.replace('.rollover p', { hover: true });

Cufon.replace(' h1', { hover: true });

Cufon.replace('#campaignNav p');

/***********************************************************************/



/* Easing Methods

************************************************************************/

easingMethod = 'easeOutCubic';



/***********************************************************************/



/* Easing

************************************************************************/

jQuery.easing['jswing'] = jQuery.easing['swing']; jQuery.extend(jQuery.easing, { def: 'easeOutQuad', swing: function (x, t, b, c, d) { return jQuery.easing[jQuery.easing.def](x, t, b, c, d); }, easeInQuad: function (x, t, b, c, d) { return c * (t /= d) * t + b; }, easeOutQuad: function (x, t, b, c, d) { return -c * (t /= d) * (t - 2) + b; }, easeInOutQuad: function (x, t, b, c, d) { if ((t /= d / 2) < 1) return c / 2 * t * t + b; return -c / 2 * ((--t) * (t - 2) - 1) + b; }, easeInCubic: function (x, t, b, c, d) { return c * (t /= d) * t * t + b; }, easeOutCubic: function (x, t, b, c, d) { return c * ((t = t / d - 1) * t * t + 1) + b; }, easeInOutCubic: function (x, t, b, c, d) { if ((t /= d / 2) < 1) return c / 2 * t * t * t + b; return c / 2 * ((t -= 2) * t * t + 2) + b; }, easeInQuart: function (x, t, b, c, d) { return c * (t /= d) * t * t * t + b; }, easeOutQuart: function (x, t, b, c, d) { return -c * ((t = t / d - 1) * t * t * t - 1) + b; }, easeInOutQuart: function (x, t, b, c, d) { if ((t /= d / 2) < 1) return c / 2 * t * t * t * t + b; return -c / 2 * ((t -= 2) * t * t * t - 2) + b; }, easeInQuint: function (x, t, b, c, d) { return c * (t /= d) * t * t * t * t + b; }, easeOutQuint: function (x, t, b, c, d) { return c * ((t = t / d - 1) * t * t * t * t + 1) + b; }, easeInOutQuint: function (x, t, b, c, d) { if ((t /= d / 2) < 1) return c / 2 * t * t * t * t * t + b; return c / 2 * ((t -= 2) * t * t * t * t + 2) + b; }, easeInSine: function (x, t, b, c, d) { return -c * Math.cos(t / d * (Math.PI / 2)) + c + b; }, easeOutSine: function (x, t, b, c, d) { return c * Math.sin(t / d * (Math.PI / 2)) + b; }, easeInOutSine: function (x, t, b, c, d) { return -c / 2 * (Math.cos(Math.PI * t / d) - 1) + b; }, easeInExpo: function (x, t, b, c, d) { return (t == 0) ? b : c * Math.pow(2, 10 * (t / d - 1)) + b; }, easeOutExpo: function (x, t, b, c, d) { return (t == d) ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b; }, easeInOutExpo: function (x, t, b, c, d) { if (t == 0) return b; if (t == d) return b + c; if ((t /= d / 2) < 1) return c / 2 * Math.pow(2, 10 * (t - 1)) + b; return c / 2 * (-Math.pow(2, -10 * --t) + 2) + b; }, easeInCirc: function (x, t, b, c, d) { return -c * (Math.sqrt(1 - (t /= d) * t) - 1) + b; }, easeOutCirc: function (x, t, b, c, d) { return c * Math.sqrt(1 - (t = t / d - 1) * t) + b; }, easeInOutCirc: function (x, t, b, c, d) { if ((t /= d / 2) < 1) return -c / 2 * (Math.sqrt(1 - t * t) - 1) + b; return c / 2 * (Math.sqrt(1 - (t -= 2) * t) + 1) + b; }, easeInElastic: function (x, t, b, c, d) { var s = 1.70158; var p = 0; var a = c; if (t == 0) return b; if ((t /= d) == 1) return b + c; if (!p) p = d * .3; if (a < Math.abs(c)) { a = c; var s = p / 4; }else var s = p / (2 * Math.PI) * Math.asin(c / a); return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;}, easeOutElastic: function (x, t, b, c, d) {var s = 1.70158; var p = 0; var a = c; if (t == 0) return b; if ((t /= d) == 1) return b + c; if (!p) p = d * .3; if (a < Math.abs(c)) { a = c; var s = p / 4; }else var s = p / (2 * Math.PI) * Math.asin(c / a); return a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) + c + b;}, easeInOutElastic: function (x, t, b, c, d) { var s = 1.70158; var p = 0; var a = c; if (t == 0) return b; if ((t /= d / 2) == 2) return b + c; if (!p) p = d * (.3 * 1.5); if (a < Math.abs(c)) { a = c; var s = p / 4; }else var s = p / (2 * Math.PI) * Math.asin(c / a); if (t < 1) return -.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b; return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p) * .5 + c + b;}, easeInBack: function (x, t, b, c, d, s) { if (s == undefined) s = 1.70158; return c * (t /= d) * t * ((s + 1) * t - s) + b; }, easeOutBack: function (x, t, b, c, d, s) { if (s == undefined) s = 1.70158; return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b; }, easeInOutBack: function (x, t, b, c, d, s) { if (s == undefined) s = 1.70158; if ((t /= d / 2) < 1) return c / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b; return c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b; }, easeInBounce: function (x, t, b, c, d) { return c - jQuery.easing.easeOutBounce(x, d - t, 0, c, d) + b; }, easeOutBounce: function (x, t, b, c, d) { if ((t /= d) < (1 / 2.75)) { return c * (7.5625 * t * t) + b; } else if (t < (2 / 2.75)) { return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b; } else if (t < (2.5 / 2.75)) { return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b; } else { return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b; } }, easeInOutBounce: function (x, t, b, c, d) { if (t < d / 2) return jQuery.easing.easeInBounce(x, t * 2, 0, c, d) * .5 + b; return jQuery.easing.easeOutBounce(x, t * 2 - d, 0, c, d) * .5 + c * .5 + b; }});

/***********************************************************************/
