﻿/** DOM-READY ****************************************************************************/
$(document).ready(function(){
    // Guided Nav!!!
    jQuery(document).ready(function(){
        GuidedNav.CustomScrollbars();
    });
    
    // Setup Previously Viewed Control
	if($('#prev_viewed').length > 0)
        PrevViewedSetup();
    if($('#BCO_UniversalBrandConnection_Header') != null)
        $('#BCO_UniversalBrandConnection_Header').css('display', 'block');
    
     //TT# 15252: Added to scroll control into view
    if(typeof controlID != 'undefined' && controlID != null && controlID.length > 0)
    {
        scrollToControl(controlID);
    }
});

//TT# 15252: Added to scroll control into view
function scrollToControl(controlID)
{
    document.getElementById(controlID).scrollIntoView(true);
}

/*****************************************************************************************/
/** [PVP] Setup **************************************************************************/
function PrevViewedSetup(){
    // Setup Item Count (Don't Count the Controller List Item)
    var pv_item_count = $('ul.pv_items li').length - 1;
    
    if(pv_item_count >= 1){
        // Update 'View All' Link Item Count
        $('#pv_viewall').html('View All (' + pv_item_count + ')');
        // Set The Controller To Open
        $('#pv_display_ctrl').addClass('open');
        // Show The List
        PrevViewedShow();
     }
     
    // Get Previously Viewed Display State From Cookie
    var state = PrevViewedCookieGetState('PreviousViewedProductsState');
    if(state == 'undefined')
        state = true;
    // Set Previously Viewed Display Based On Cookie
    PrevViewedCookieCtrl(state);
}
/** [PVP] Show ***************************************************************************/
function PrevViewedShow(){
    // Show The List
    $('#prev_viewed').css('visibility', 'visible');
}
/** [PVP] Hide ***************************************************************************/
function PrevViewedHide(){
    // Hide The List
    $('#prev_viewed').css('display', 'none');
    // Remove Body Min-Width 
    $('body').css('min-width', '0');   
    $('#container').css('display', 'block');  
    $('#RM_UniversalBrandConnection_Header').css('display', 'block');  
}
/** [PVP] Justify Alignment for low resolution *******************************************/
function AlignLeft(){
    $('#container').css('float', 'left');     
    $('#RM_UniversalBrandConnection_Header').css('float', 'left');     
}
/** [PVP] Display Controller *************************************************************/
function PrevViewedCtrl(){
	if($('#pv_display_ctrl').attr('class') == 'open'){
		// Collapse Previously Viewed Content
		PrevViewedCtrlCollapse();
		// Set Display State Cookie (Closed)
		PrevViewedCookieSetState(false);
	} 
	else if($('#pv_display_ctrl').attr('class') == 'closed'){
        // Expand Previously Viewed Content
		PrevViewedCtrlExpand();
		// Set Display State Cookie (Open)
		PrevViewedCookieSetState(true);
}}
/** [PVP] Show Display *******************************************************************/
function PrevViewedCtrlShow(){
    // Enable Display
    $('#prev_viewed .content').css('display', 'block');
	// Change Display Controller Icon
	$('#pv_display_ctrl').removeClass('closed');
	$('#pv_display_ctrl').addClass('open');
	// Manually Change Controller Icon for IE6
	if($.browser.msie && $.browser.version.substr(0,1) < 7)
		$('#pv_display_ctrl').css('background-position', 'top left');
	// Show Bottom Border
	$('#prev_viewed li.top').css('border-bottom', '1px solid ' + $('#prev_viewed').css('border-top-color'));
}
/** [PVP] Hide Display *******************************************************************/
function PrevViewedCtrlHide(){
    // Disable Display
    $('#prev_viewed .content').css('display', 'none');
	// Change Display Controller Icon
	$('#pv_display_ctrl').removeClass('open');
	$('#pv_display_ctrl').addClass('closed');
	// Manually Change Controller Icon for IE6
	if ($.browser.msie && $.browser.version.substr(0,1)<7)
		$('#pv_display_ctrl').css('background-position', 'top right');
	// Hide Bottom Border
	$('#prev_viewed li.top').css('border-bottom', 'none');
}
/** [PVP] Expand Display *****************************************************************/
function PrevViewedCtrlExpand(){
    $('#prev_viewed .content').slideDown('normal');
	// Change Display Controller Icon
	$('#pv_display_ctrl').removeClass('closed');
	$('#pv_display_ctrl').addClass('open');
	// Manually Change Controller Icon for IE6
	if($.browser.msie && $.browser.version.substr(0,1) < 7)
		$('#pv_display_ctrl').css('background-position', 'top left');
	// Show Bottom Border
	$('#prev_viewed li.top').css('border-bottom', '1px solid ' + $('#prev_viewed').css('border-top-color'));
}
/** [PVP] Collapse Display ***************************************************************/
function PrevViewedCtrlCollapse(){
	$('#prev_viewed .content').slideUp('normal');
	// Change Display Controller Icon
	$('#pv_display_ctrl').removeClass('open');
	$('#pv_display_ctrl').addClass('closed');
	// Manually Change Controller Icon for IE6
	if ($.browser.msie && $.browser.version.substr(0,1)<7)
		$('#pv_display_ctrl').css('background-position', 'top right');
	// Hide Bottom Border
	$('#prev_viewed li.top').css('border-bottom', 'none');
}
/** [PVP] Cookie Controller **************************************************************/
function PrevViewedCookieCtrl(value){
	if(value=='false')
		// Hide Previously Viewed Content
		PrevViewedCtrlHide();
	else if(value=='true')
		// Show Previously Viewed Content
		PrevViewedCtrlShow();
}
/** [PVP] Set Cookie State ***************************************************************/
function PrevViewedCookieSetState(pvpState, path, domain, secure){
    var cookieName = 'PreviousViewedProductsState';
    var today = new Date();
    var thisCookie = cookieName + "=" + pvpState +
	((path) ? "; path=" + path :"; path=/") +
	((domain) ? "; domain=" + domain : "") +
	((secure) ? "; secure" : "");
	document.cookie = thisCookie;
}
/** [PVP] Get Cookie State ***************************************************************/
function PrevViewedCookieGetState(name){
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen){
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
		return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break; 
	}
	return null;
}
/**** [END] PREVIOUSLY VIEWED PRODUCTS ***************************************************/
// Javascript popup control script 'Helper functions'
function isNull(obj)
   {return (typeof(obj) === "undefined" || obj == null);}

var screen_width;
var screen_height;

function ensureScreenDimensions()
{
    if(screen_width == null || screen_height == null)
    {
        if (typeof(window.innerWidth) == 'number') { 
		    screen_width = window.innerWidth;
		    screen_height = window.innerHeight;
	    } else if (document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight)) {
		    // IE6+ in 'standards compliant mode'
		    screen_width = document.documentElement.clientWidth;
		    screen_height = document.documentElement.clientHeight;
	    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		    // IE4-compatible...?
		    screen_width = document.body.clientWidth;
		    screen_height = document.body.clientHeight;
}}}
function screenWidth()
   {ensureScreenDimensions();
    return screen_width;}

function screenHeight()
   {ensureScreenDimensions();
    return screen_height;}

var jsPopup = { // jsPopup object
    popupWindow: null,    
    open: function(url, launchButtonID, width, height)
    {
        // Create the quickview window
        var left, top;
        popupWindow = dhtmlwindow.open("popupWindow", "iframe", url, "", "width=" + width + ",height=" + height);
        
        // if located launch button
        var launchButton = document.getElementById(launchButtonID);
        if(!isNull(launchButton))
        {
            // Calculate the left and top positions for the window
            left = launchButton.offsetLeft - (popupWindow.clientWidth - launchButton.offsetWidth) / 2;
            var right = left + popupWindow.clientWidth;
            if(left < 0)
                {left = 0;}
            else if(right > screenWidth())
                {left = screenWidth() - popupWindow.clientWidth;}
            
            top = (screenHeight() - popupWindow.clientHeight) / 2;
            var bottom = top + popupWindow.clientHeight;
            if(top < 0)
                {top = 0;}
            else if(bottom > screenHeight())
                {top = screenHeight() - popupWindow.clientHeight;}
            
            // Move the window to calculated left and top
            dhtmlwindow.moveTo(popupWindow, left, top);
        }
        
        return popupWindow;
    },
    
    showControl: function(controlId)
    {
        if(!isNull(controlId))
        {
            var control = document.getElementById(controlId);
            if(!isNull(control))
                 {control.style.display = "block";}
        }
    },
    
    hideControl: function(controlId)
    {
        if(!isNull(controlId))
        {
            var control = document.getElementById(controlId);
            if(!isNull(control))
                 {control.style.display = "none";}
        }
    },
    
    close: function()
    {
        dhtmlwindow.close(popupWindow);
        document.getElementById('quickinfooverlay').style.display = 'none';
    }
};
/////////////////////under layer
          function onQuickViewLoad()  
          {  
             var iframe = document.createElement("iframe");
             iframe.setAttribute("id", "under_tt");
             iframe.frameBorder = "0";
             var popupWindow = document.getElementById("popupWindow");  
             popupWindow.appendChild(iframe);  
          }  



/* ENDECA CUSTOM SCROLL BARS ´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·. */

var GuidedNav = {
    CustomScrollbars : function() {
        // decide how scroll bars get allotted
        var scroll_threshhold = 99999; /* default is no scroll bars */
        if (jQuery('div#product-list').length > 0) { scroll_threshhold = 10; }
        if (location.href.match('SearchResults.aspx')) { scroll_threshhold = 5; }
        
		// find left nav elements that need scroll bars
		jQuery.each(jQuery('ul[class*="filter_value"]'), function() {
			if (jQuery(this).find('li').size() > scroll_threshhold) {
				jQuery(this).addClass('scroller');
			} else {
			    // remove fixed-height hack for everyone else
			    jQuery(this).css('height', 'auto');
			    jQuery(this).css('padding-bottom', '5px');
			}
		});
		// a little housecleaning...
		jQuery('#left-nav .mui_gn').css('height', 'auto');
		jQuery('#left-nav .mui_gn').css('margin-bottom', '-10px');
		// time for the scrollbars
		jQuery('#left-nav ul.scroller').jScrollPane({ dragMaxHeight:43, scrollbarWidth:13 });
		// IE6 hides categories (without the timeout, this fix won't work)
        if (jQuery.browser.msie && jQuery.browser.version <= 6) { 
            var ie6_fix = setTimeout("jQuery('.mui_gn').css('display','inline-block')",99);
        }	
		// scroll to a selected attribute (if possible)
		if (jQuery('#department-nav .category_selected').length > 0 && jQuery('#department-nav .mui_gn_filter_value').is('.scroller')) {
		    jQuery('#left-nav .mui_gn_filter_value')[0].scrollTo('.category_selected');
		};	
    }
}

/* [END] ENDECA CUSTOM SCROLL BARS .¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯` */
