/* Utility.js */

jQuery(document).ready(function() {

    // activate product page 'fakeDD' Sears DHTML
    $('#product .fakeDD').click(function(){
        //console.log('Received click: %o',$(this));
        if ((SEARS.Item) && (typeof SEARS.Item.fakeDDshow === "function")) {
            //console.log('running Sears function fakeDDshow()');
            SEARS.Item.fakeDDshow();
        }
    });
    // display lightbox on page load via query string
    lightboxByQueryString();

	// handles ff2 footer issue
    if ($.browser.mozilla && ($.browser.version < 3)) {
        $('#footer #footerContent ul li.headline').css("background-position", "0 3px !important");
    }

	// handles Compare Items table width issue.
	if($('#mainCompareTable').length > 0) {
        if ($('#mainCompareTable').width() > 950) {
		    //$('#wrapper').css("min-width", $('#mainCompareTable').width() );
            var tableW = $('#mainCompareTable').width();
            //console.log('mainCompareTable is too big for default min-width. Setting min-width on same elements to "%s"',tableW);
		    $('#header').css("min-width", tableW );
		    $('#breadcrumb').css("min-width", tableW );
		    $('#content').css("min-width", tableW );
        }
	}

	//fix for dropdown over select boxes.
    $('.sub').bgiframe();
	
    /* for tables matching classname for collapsable behavior, 
       create an instance of CollapsableTable class and load it into
       globally available array */
    CollapsableTables = new Array();
    var tableSelector = '.collapsableTable';
    $(tableSelector).each(function(){
        var newCT = new CollapsableTable({ "tableSelector": tableSelector }); 
        CollapsableTables.push(newCT);
    });
	
	// compare products table
	if ($('#mainCompareTable').length > 0) {
		$('#content').css("min-width", $('#mainCompareTable').width());
		$('#showDetails').click(function() {
			$('#mainCompareTable td.category').addClass("open");
			$('#mainCompareTable td.category table').css("display", "block");
		});
		$('#hideDetails').click(function() {
			$('#mainCompareTable td.category').removeClass("open");
			$('#mainCompareTable td.category table').css("display", "none");
		});
		$('#mainCompareTable td.category h3').click(function() {
			$(this.parentNode).toggleClass("open");
			$(this.parentNode).children("table:eq(0)").slideToggle("fast");
		});
		$('#mainCompareTable td.category .tableProductCompare td').mouseover(function() {
			$(this.parentNode).addClass("hover");
		});
		$('#mainCompareTable td.category .tableProductCompare td').mouseout(function() {
			$(this.parentNode).removeClass("hover");
		});
	}
	
	// carousel tabs 
	$('.tabs li a').click(function() {
		$('.tabs li').each(function(node) {
			$(this).removeClass("selected");
		});
		$(this.parentNode).addClass("selected");								
	});
	
	// product listing item shown tabs
	$('#subcategory #sortByBar #itemShown ul li a').click(function() {
		$('#subcategory #sortByBar #itemShown ul li a').each(function(node) {
			$(this).removeClass("on");
		});
		$(this).addClass("on");								
	});
	
	// search results item shown tabs 
	$('#searchResults #sortByBar #itemShown ul li a').click(function() {
		$('#searchResults #sortByBar #itemShown ul li a').each(function(node) {
			$(this).removeClass("on");
		});
		$(this).addClass("on");								
	});
	
	// search results item shown tabs 
	$('#searchResults .dlWrap dl dt a').click(function() {
		$('#searchResults .dlWrap dl dt a').each(function(node) {
			$(this.parentNode).removeClass("active");
		});
		$(this.parentNode).addClass("active");								
	});
	
	// product detail color swatches
	$('div.color a').click(function() {
		if ( $(this).html() == "[Edit]" ) {
			$(this).html("[close]");
			$('div.colors').show('blind',{},1000);
		} else {
			$(this).html("[Edit]");
			$('div.colors').hide('blind',{},1000);
		}
	});
	$('div.colors ul li a').click(function() {
		$('div.color span').html($(this).children("img").attr("alt"));
		//$('div.color a').html("[Edit]");
		//$('div.colors').hide('blind',{},1000);
	});


	$('.sendalert .lb_content .lb_inputs a.ok').click(function() {
		hidebox('#lb_sendalert');
		showbox('#lb_sendalertThanks');
	});
	
	// product detail thumbnails 
	$('ul.thumbs li a').click(function() {
									   
		$('ul.thumbs li a').each(function() {
			if ($(this).hasClass("selected")) {
				$(this).removeClass("selected");
			}
		});
									   
		if (!($(this.parentNode).hasClass("video")) || (!($(this.parentNode).hasClass("video-nomsg")))) {
			$('#zoomImg').children("img").attr("src", $(this).children("img").attr("src").replace('.jpg','.med.jpg'));
			$('#zoomImg').children("img").attr("height", 400);
			$('#zoomImg').children("img").attr("width", 400);
			
			$(this).addClass("selected");
		}
	});
	
	// product detail - no results
	$('#noresults input').click(function() {
		$('#noresults').hide();
		$('#body-curtain').attr("style", "display:none !important");								 
	});
	
	
});

function changeLayout(i) {
    var flashWrap = $('#ProductDetailsHolder');
    var flash = $('#ProductDetailsHolder embed');
    if ($(flash).length < 1) {
        flash = $('#ProductDetailsHolder object');
    }
    //document.getElementById("ProductDetailsHolder").style.height = i + "px";
    //window.status = i;
    if ($(flashWrap).length && $(flash).length){
        $(flashWrap).height(i + "px")
        $(flash).height(i + "px")
    }
}
function openRebate() {
    //console.log('openRebate() running...');
    window.status = 'openRebate';
}

function CollapsableTable(ArgumentsObj) {
    /* Argument Defaults */
    var NewArguments = {
        tableSelector: false
    };
    /* Replace Default Args with New Args */
    for (var argName in ArgumentsObj) {
        NewArguments[argName] = ArgumentsObj[argName];
    }
    /* Set Properties with Latest Arguments */
    this.tableSelector = NewArguments.tableSelector;
    
    var self = this;

    self.init = function() {
        self.layoutContainer = $("#content");
        self.parentSelector = "#content .firstCol";
        self.table = $(self.tableSelector);
        self.innerCellSelector = self.tableSelector+" table td";
        self.headerClass = "headCol";
        self.toggleSelector = self.tableSelector+" td.category h3";
        self.toggleClass = "open";
        self.hoverClass = "hover";
        // account for left edge positioning of the table so resultant with
        // has right edge of table aligned with page content
        
		
		if ($.browser.msie && ($.browser.version == 6.0)) {
            // always use a zero static offset for IE6 otherwise the table will be 
            // wider than its container. Next time resize is done the larger container
            // width feeds back into itself, causing un-ending expansion of table/document
            self.staticLayoutOffset = 0;
            //self.staticLayoutOffset = -22;
        } else {
            // these values are in external CSS so must be kept in sync
            if ($('body').hasClass('customerService')){
                //self.staticLayoutOffset = 12;
				self.staticLayoutOffset = -10;
            } else {
                self.staticLayoutOffset = 20;
            }
        }
		
		
        // head column is 191px w/padding and w/borders on left and right
        // head column is 181px w/padding and w/borders on left and right
        self.headColWidth = 193;
        self.headColWidth = 181;
        // general padding for columns, if changed in css change here also
        self.tableColPadding = 36;
    
        self.numColumnsMinusHeadCol = $(self.tableSelector+' table:eq(0) tr:eq(0) td').length - 1;
        
        self.registerEvents();
        self.resizeTable();
    }

    self.setLayoutWidthForTable = function() {
		$(self.layoutContainer).css("min-width", $(self.table).width());
    }

    self.registerEvents = function() {
        //console.log('collapsable table for object %o running registerEvents()',self);
		$(self.toggleSelector).click(function() {
			$(this.parentNode).toggleClass(self.toggleClass);
			$(this.parentNode).children("table:eq(0)").slideToggle("fast");
		});
		$(self.innerCellSelector).mouseover(function() {
			$(this.parentNode).addClass(self.hoverClass);
		});
		$(self.innerCellSelector).mouseout(function() {
			$(this.parentNode).removeClass(self.hoverClass);
		});
        if ($.browser.msie) {
            var delayTableResize = setInterval(function(){ self.resizeTable(); },1000);
        } else {
            $(window).resize(self.resizeTable);
        }
    }
		
    self.tableWidthMinusHeadCol = function() {
        var width = $(self.table).width() - self.headColWidth;
        return width;
    }

    self.newCellWidth = function() {
        // calculate # columns to assign width outside of head column
        var newWidth = ((self.tableWidthMinusHeadCol() - self.numColumnsMinusHeadCol) / self.numColumnsMinusHeadCol) - self.tableColPadding;

        // convert floating point cell width to integer
        if (self.isInteger(newWidth) == false) {
            // if value is not integer, than it's 0.5, which gets rounded down.
            // add 1 to get a 'rounding up' effect
            newWidth = Math.round(newWidth) + 1;
        }
        //console.log("resizeCollapsableTables(): setting new width as \"%s\"",newWidth);
        return newWidth;
    }

    self.isInteger = function(value) {
        var result = (value.toString().search(/^-?[0-9]+$/) == 0);
        return result;
    }

	// resizing collapsable tables
    self.resizeTable = function() {
        var tableContainer = $(self.table).parent().get(0);
        // Jquery is returning wrong value using width(). It is out-of-date if makeLayoutElastic()
        // reduces its width from a larger size. width() reports the larger value, not the new one
        var containerW = tableContainer.clientWidth;
        var containerW = $(self.parentSelector).width();
	    if ($.browser.msie) {
            var newTableWidth = tableContainer.style.width;
        } else {
            var newTableWidth = containerW + self.staticLayoutOffset;
        }
	    $(self.table).css("width", newTableWidth);
	    $(self.innerCellSelector).each(function(node) {
		    if (!($(this).hasClass(self.headerClass))) {
			    $(this).css("width", self.newCellWidth());
		    }
	    });
        //var sampleW = $('.collapsableTable table .headCol').width();
        //var alertContent = "Resized Collapsable Table according to these params: "; 
        //alertContent +=  "\nnew table width as "+newTableWidth+" vs. Jquery "+newTableWidth;
        //alertContent +=  "\ntableWidthMinusHeadCol '"+self.tableWidthMinusHeadCol()+"'";
        //alertContent +=  "\nhave sample .headerCol width '"+sampleW+"'";
        //alertContent +=  "\nnewCellWidth as '"+self.newCellWidth()+"'";
        //alert(alertContent);
        //console.log(alertContent);
    }

    self.init();
}


jQuery(function($) {
	
    var h1 = $('h1');
    if (h1.length) {
	    $(h1).pngfix();		
    }
	
	if ($('#advantage').length) {
		$('#projectEdison span').pngfix();
	}
	
	//inline images with .png class on em.
	var myPngz = $('img.png');
    if (myPngz.length) {
	    $(myPngz).pngfix();
    }

});

jQuery(document).ready(function() {
	
	var accordionHeight;
	var accordionLinkHeight;
	
	$('#leftCol li.open li a').each(function(node){
		if ($(this).next('ul').length == 0) {
			$(this).css("background-image", "none");
		}
	});

	$('#leftCol li.open li a').each(function(node){
		if ($(this).next('ul') && !($(this.parentNode).hasClass('open'))){
			$(this.parentNode).height($(this).outerHeight());
		};
		$(this).next('ul').show();
	});

	$('#leftCol ul li.open ul li a').click(function() {
		if ($(this).next('ul').length > 0) {
			if ($(this.parentNode).hasClass('open')) {
		        var accordionLinkHeight = $(this).outerHeight();
				//$(this.parentNode).animate({ height: accordionLinkHeight }, 'fast', 'swing', $(this.parentNode).toggleClass('open'));
                $(this).next().hide();
                $(this.parentNode).css({ height:"" });
				$(this.parentNode).toggleClass('open')
			} else {
                var clicked = this;
                $(this).next().show(1,function(){
		            var accordionHeight = $(this).outerHeight();
                    var maxHeight = 200;
                    var openHeight = 0;
                    if (maxHeight > accordionHeight) {
                        openHeight = accordionHeight;
                    } else {
                        openHeight = maxHeight;
                        $(this).css({ "overflow-y" : "auto", "overflow-x" : "hidden" });
                    }
                    // for IE, set height of parent to opened element + anchor 
                    var parentHeight = $(clicked).outerHeight() + openHeight;
                    $(this.parentNode).height(parentHeight);

                    // set height of opened element to new neight
                    $(this).height(openHeight);
				    $(this.parentNode).addClass('open');
                    //console.log('opening left nav filter group, to height "%s", set parent to "%s"; based on accordionHeight "%s" and maxHeight "%s"',openHeight,parentHeight,accordionHeight,maxHeight);
                    //alert('opening left nav filter group, to height "'+openHeight+'", based on accordionHeight "'+accordionHeight+'" and maxHeight "'+maxHeight+'"');
                });
				//$(this.parentNode).animate({ height: openHeight }, 'fast', 'swing');
			}
		};
		return false;
	});
	
	var sliderStart = $('.filters div.sliderMax').text().replace('$','');

    /* handling a.clearAll click in subcat_Dk.js 
	$('#leftCol .filters a.clearAll').click(function() {
		$(this).nextAll('ul').find('input:checkbox').removeAttr("checked");
		$(".filters .ui-slider").slider('moveTo', sliderStart, 1, true);
		$('.filters div.sliderMax').text( '$' + sliderStart );
		$('.filters div.ui-slider input').val( sliderStart );
		return false;
	}); */

    /* handling filter clear click in subcat_Dk.js
	$('#leftCol .filters a.clear').click(function() {
		$(this).nextAll('ul').find('input:checkbox').removeAttr("checked");
		return false;
	});*/

	if ($(".filters .ui-slider").length > 0) {
	
		$(".filters .ui-slider").slider({
			animate: false,
			range: true,
			min: 0,
			max: sliderStart,
			handles: [ 
				{start: 0, min: 0, max: 0}, 
				{start: sliderStart, min: 1, max: sliderStart} 
			],
			slide: function(event, ui) {
				$('.filters div.sliderMax').text( '$' + $(this).slider('value') );
				setRangeValue();
			},
			change: function(event, ui) {
                var userValue = $(".filters .ui-slider").slider('value');
				$('.filters div.ui-slider input').val(userValue);
                /* integrate with Sears filters from subcat_Dk.js */
                if (userValue != sliderStart) {
                    $(".filters .ui-slider").addClass("selected");
                } else {
                    $(".filters .ui-slider").removeClass("selected");
                }
                /* integrate with Sears filters from subcat_Dk.js */
                if (typeof priceClickJson === "function") {
                    priceClickJson(); 
                }
			}
		});

		setRangeValue();
        // set input based on layout default 
        var userValue = $(".filters .ui-slider").slider('value');
	    $('.filters div.ui-slider input').val(userValue);
	
	}

	function setRangeValue() {
		var priceWidth =  (3 - ($('.filters div.sliderMax').width() / 2)) + 'px';
		$('.filters div.sliderMax').css({ left: priceWidth })
	}

});


jQuery(document).ready(function() {
    /*
	var selector = '.tabSwitcher dl';
    $(selector).each(function() {
        var tabSwitcher = new TabSwitcher({controlSelector:selector+' dt',tabSelector:selector+' .tab',tabActiveClass:'active',tabHoverClass:'active'});
    }); */

    var controlSelector = '.quickView .tabs li';
    var tabSelector = '.quickView .content > div';
    DocumentTabs = new Array();
    $('.quickView .tabs').each(function(){
        var tabSwitcher = new TabSwitcher({controlSelector:controlSelector,tabSelector:tabSelector,tabActiveClass:'active',tabHoverClass:'active'});
        DocumentTabs.push(tabSwitcher);
    });
	
	var prodControlSelector = '.tabSwitcher dl dt';
	var prodTabSelector = '.tabSwitcher dl dd.tab .firstCol > div';
	$('.dlWrap').each(function(){
        var tabSwitcher = new TabSwitcher({controlSelector:prodControlSelector,tabSelector:prodTabSelector,tabActiveClass:'active',tabHoverClass:'active'});
        DocumentTabs.push(tabSwitcher);
    });

	var prodControlSelector = '.tabSwitcher ul li';
	var prodTabSelector = '.detailContent .firstCol > div';
	$('.prodContent').each(function(){
        var tabSwitcher = new TabSwitcher({controlSelector:prodControlSelector,tabSelector:prodTabSelector,tabActiveClass:'active',tabHoverClass:'active'});
        DocumentTabs.push(tabSwitcher);
    });
	
});

var TabSwitcher = function(ArgumentsObj) {
    /* Argument Defaults */
    var NewArguments = {
        controlSelector: false,
        tabSelector: false,
        tabActiveClass: 'tabActive',
        tabHoverClass: 'tabHover'
    };
    /* Replace Default Args with New Args */
    for (var argName in ArgumentsObj) {
        NewArguments[argName] = ArgumentsObj[argName];
    }
    /* Set Properties with Latest Arguments */
    this.controlSelector = NewArguments.controlSelector;
    this.tabSelector = NewArguments.tabSelector;
    this.tabActiveClass = NewArguments.tabActiveClass;
    this.tabHoverClass = NewArguments.tabHoverClass;

    /* Other Properties */
    this.tabControls = new Array();

    this.init = function(){
        var controls = $(self.controlSelector);
        $(controls).each(function(){
            self.tabControls.push({ DOMObj: this, active: false });
        });
        self.tabs = $(self.tabSelector);
        self.registerEvents(); 
        self.showTab(0);
    }
    this.registerEvents = function() {
        //console.log('registerEvents() for object %o',self);
        $(self.tabControls).each(function(index){
            var tC = this;
            $(tC.DOMObj).click(function(){ self.showTab(index); });
            $(tC.DOMObj).mouseover(function(){ $(this).addClass(self.tabHoverClass); });
            $(tC.DOMObj).mouseout(function(){
                /* handle edge case where hover and active class are same name */
                if (self.tabActiveClass === self.tabHoverClass){ 
                    if (tC.active) {
                        /* don't remove the classname, it's the active state */
                    } else {
                        $(this).removeClass(self.tabHoverClass);
                    }
                }
            });
        });
    }
    this.showTab = function(tabRef) {
        var tab = false;
        var tabNumb;
        if (self.isInteger(tabRef)) {
            tabNumb = tabRef;
        } else {
            tabJ = $('.'+tabRef);
            var allTabs = $(tabJ).parent().children();
            $(allTabs).each(function(i){
                if ($(this).hasClass(tabRef)) {
                    tabNumb = i;
                }
            });
        }
        tab = self.tabs[tabNumb];
        //console.log('showTab(): selected tab as "%o"',tab);
        /* only switch if new tab body exists */
        if (tab) {
            self.hideTabs();
            self.tabControls[tabNumb].active = true;
            $(self.tabControls[tabNumb].DOMObj).addClass(self.tabActiveClass);
            $(tab).show();
        }
    }
    this.hideTabs = function() {
        $(self.tabControls).each(function(index) {
            this.active = false;
            $(this.DOMObj).removeClass(self.tabActiveClass);
        });
        $(self.tabs).each(function(index){
            $(this).hide();
        });
    }
    this.isInteger = function(s) {
        return (s.toString().search(/^-?[0-9]+$/) == 0);
    }

    var self = this;
    self.init();
}

function lightboxByQueryString() {
    var self = this;
    self.init = function() {
        /* set properties */
        self.locationStr = window.location.toString();
        self.delimiter = "#";
        self.query = "";
        self.lightboxIDRegex = /^lb_.*?$/;

        /* run methods */
        self.parseQuery();
        self.evaluateQuery();
    }
    self.parseQuery = function() {
        var matchIndex = self.locationStr.lastIndexOf(self.delimiter);
        var queryStr = self.locationStr.substr(matchIndex+1);
        self.query = queryStr;
        //console.log('have query string as "%s", found position of # as "%s", gaining result of "%s"',self.locationStr,matchIndex,queryStr);
    }
    self.evaluateQuery = function () {
        if (self.query.match(self.lightboxIDRegex)) {
            //console.log('have match');
            self.doLightbox();
        }
    }
    self.doLightbox = function() {
        if (typeof showbox === "function") {
            var argString = '#'+self.query;
            showbox(argString);
        }
    }
    
    self.init();
}

// Lightbox
// calculate viewport & offset dimensions
function viewPortHeight() { 
	return self.innerHeight || document.documentElement.clientHeight || document.body.clientHeight; }
function viewPortWidth() { 
	return self.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;}
function scrollOffsetHeight() { 
	return self.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;}
function scrollOffsetWidth() { 
	return self.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft;}
function documentHeight() {
    var myHeight = 0;
    if (document.documentElement) {
        myHeight = document.documentElement.scrollHeight;
    } else if (document.body) {
        myHeight = document.documentElement.scrollHeight;
    }
    return myHeight;
}



function showbox(el, returnToQuickView) {
    // el: layout box to show
    // returnToQuickView: Integration with external Sears function,
    //   used for custom flow where we always return to Quick View 
    //   if showbox() has been called from Quick View
    //console.log('showbox("%s",%s)...',el,returnToQuickView);

    // hide any other lightboxes that are showing
	$(".lightbox").hide();		
	// hide zipFinder
	$("#zipFinder").hide();

	// compute the height and width of the overlay
	// $("#overlay").css("height",Math.round($(el).height() + 28));
	// 		$("#overlay").css("width",Math.round($(el).width() + 28));
    var oHeight = documentHeight();
	var oWidth = viewPortWidth();
	$("#overlay").css("height",oHeight);
	//$("#overlay").css("width",oWidth);
		
							
	// setup positioning for lightbox (centered)	
	$(el).css("left",Math.round(viewPortWidth()/2) + scrollOffsetWidth() - Math.round($(el).width()/2));
	$(el).css("top",Math.round(viewPortHeight()/2) + scrollOffsetHeight() - Math.round($(el).height()/2));
		
	// setup positioning for the overlay (centered) 
	// $("#overlay").css("left",Math.round(viewPortWidth()/2) + scrollOffsetWidth() - Math.round($(el).width()/2 + 14));
	// 		$("#overlay").css("top",Math.round(viewPortHeight()/2) + scrollOffsetHeight() - Math.round($(el).height()/2 + 14));	
	$("#overlay").css("left",0);
	$("#overlay").css("top",0);	
		
    // based on optional argument, re-open Sears Quick View if it was closed for this showbox()
    if (returnToQuickView) {
        $(el).find('a.close').unbind().click(function(){
            //console.log('doing return to Quick View routines....');
            hidebox(el);
            if ((SEARS.QuickView) && (typeof SEARS.QuickView.launch == "function")) { // external
                SEARS.QuickView.launch();
            }
        });
    } else {
        $(el).find('a.close').unbind().click(function(){
            //console.log('hiding box, no return to Quick View....');
            hidebox(el);
        });
    }
	// show lightbox
	$(el).show();
	
	// show overlay 
	$("#overlay").show().bgiframe();

    /* older handling for arguments no longer used 
		//add checked class if toggle is set to true
		//toggle ? $(cEl).addClass("checked") :"";
	if (overlay == null) {
	} else {
        //console.log('showbox()... argument "overlay" is not NULL, have cEl as %o',cEl);
	
		// find the offsets of the clicked element
		var offset = $(cEl).offset();
		
		// calculate position relative to clicked element				
		$(el).css("left",offset.left + $(cEl).width() + 10);
		$(el).css("top",offset.top + 5);
     } */
	
}

function hidebox(el, overlay) {
	// hide lightbox
	$(el).hide();
	
	// hide overlay if there is one
	if (overlay == null) {
		$("#overlay").hide();
	}
}

function showpickup(el) {
	$(".lb_inputs").hide();
	$(el).show();
	$("#overlay").css("height",Math.round($(".addtocart").height() + 28));
	$("#overlay").show();
}

// Toggles the shareStory and bookmarks divs on the Product Detail Page

function toggleshare() {
	$(".saveStory").toggle();
	$(".bookmarks").toggle();
	$(".shareItem").toggleClass('active');
}

/*Stores or deletes the product details when selected or deselected for Comparing - FROM SEARS*/

function setCheck(box){
 	//If checked

    if(box.checked==true){
    	// if(jsonProperties.enableATO_STL == true){
    	//             $(box).parent().parent().parent().addClass('selected');
    	//         }
    	//         else{
    	//         	box.parentNode.parentNode.parentNode.className="product selected";
    	//         }

		box.parentNode.parentNode.parentNode.className="product selected";
		
        // var partNumber = box.name;
        //          for(i=0;i<partNumberValues.length;i++){
        //             if(partNumberValues[i]=='' || partNumberValues[i]==null){
        //                 partNumberValues[i]=partNumber;
        //                 break;
        //             }
        //          }          
        // 
        //          prodCountCompare++;
        //          if(prodCountCompare > maxCompares) {
        //             partNumberValues[--prodCountCompare]='';
        // 
        //             //do not allow to check more than max
        //             box.checked=false;
        // 
        //             //also remove the css
        //             if(jsonProperties.enableATO_STL == true){
        //             	$(box).parent().parent().parent().removeClass('selected');
        //            	}
        //            	else{
        //             	box.parentNode.parentNode.parentNode.className="product";
        //            	}
        // 
        //             alert("You can compare a maximum of "+maxCompares+" items");
        //          }

    }else{

        //if unchecked
        // prodCountCompare--;
        //         if(jsonProperties.enableATO_STL == true){
        //         	$(box).parent().parent().parent().removeClass('selected');
        //        	}
        //        	else{
        //         	box.parentNode.parentNode.parentNode.className="product";       
        //        	}

		box.parentNode.parentNode.parentNode.className="product";   
		
        // var partNumber = box.name;
        //         for(i=0;i<partNumberValues.length;i++){
        //             if(partNumberValues[i]==partNumber){
        //                 partNumberValues[i]='';
        //             }
        //         }
    }
}



/*When the compare button is clicked - FROM SEARS*/

function compareProducts(){
    var j=0;

    if(prodCountCompare > 1 ){
    	compareParam=compareUrl();
        for(i=0;i<partNumberValues.length;i++) {
            if(partNumberValues[i]!='' && partNumberValues[i]!=null ) {
                j++;
                var temp='&partNumber_'+j+'=';
                compareParam=compareParam+temp+partNumberValues[i];
            }
        }

        compareParam=compareParam+'&prodCount='+j;
        window.location.href=compareParam;
    }
    else{
        alert("You must select atleast 2 items to compare");
    }
}

/* End Compare Products */


// jQuery(function($){
// 	jQuery.fn.imgZoom = function(settings){
// 		settings = jQuery.extend({// Default settings...
// 			container:  'body',
// 			src:		'img/fullsize.jpg',
// 			hideIt:		false
// 		}, settings);
// 		return this.each(function(i){
// 			var set = new Array();
// 			if($(this).is('img')){
// 				set.push(this);
// 			}else{
// 				$(this).find('img').each(function(){
// 					set.push(this);
// 				});
// 			};
// 			$(set).each(function(i){
// 				var global = this;
// 				var zoomtainer = settings.container;
// 				var maxH, maxW, helperHalf, scaleFactor, zoomedSize, helperSize;
// 				var ourSize = { width:$(this).width(), height:$(this).height() };
// 				$(this).wrap('<div class="zzz_imgzoom"/>');
// 				var currentContainer = $(this).parent();
// 				$(currentContainer).css({
// 					width:		$(this).width(),
// 					height:		$(this).height(),
// 					overflow:	'hidden',
// 					position:	'relative'
// 				});
// 				$(zoomtainer).css({
// 					position:	'relative',
// 					overflow:	'hidden'
// 				});
// 				var shade = $('<div class="zzz_shade"/>').css({ 
// 					width:		$(currentContainer).width(),
// 					height:		$(currentContainer).height(),
// 					display:	'none',
// 					position:	'absolute',
// 					top:		0,
// 					left:		0,
// 					background:	'url(img/loading.gif) no-repeat center center #fff',
// 					opacity:	0.75,
// 					filter:		'alpha(opacity=75)'
// 				}).appendTo(currentContainer);;
// 				var helper = $('<div class="zzz_imghelper"/>').css({
// 					border:		'1px solid #fff',
// 					background:	'url('+$(this).attr('src')+') no-repeat -1px -1px #fff',
// 					display:	'none',
// 					position:	'absolute',
// 					top:		0,
// 					left:		0
// 				}).appendTo(currentContainer);;
// 				var zoomed = $('<div class="zzz_zoomed"/>').hide().css({
// 					overflow:	'hidden', 
// 					background:	'url(img/loading.gif) center center no-repeat #fff',
// 					position:	'absolute',
// 					height:		$(zoomtainer).height(),
// 					width:		$(zoomtainer).width(),
// 					top:		$(zoomtainer).css('padding-top'),
// 					left:		$(zoomtainer).css('padding-left')
// 				}).appendTo(zoomtainer);
// 				
// 				$(currentContainer).unbind().hover(function(){
// 					$(shade).fadeIn(200);
// 					$(helper).fadeIn(200);
// 					$(zoomed).fadeIn(200);
// 					if(settings.hideIt){
// 						$(zoomtainer).show()
// 					}
// 				},function(){
// 					$(shade).fadeOut(200);
// 					$(helper).fadeOut(200);
// 					$(zoomed).fadeOut(200);
// 					if(settings.hideIt){
// 						$(zoomtainer).hide()
// 					}
// 				});
// 				var zoomedImg = new Image();
// 				zoomedImg.onload = function(){
// 					zoomedSize = { width:zoomedImg.width, height:zoomedImg.height };
// 					scaleFactor = { x:(zoomedSize.width/ourSize.width), y:(zoomedSize.height/ourSize.height) };
// 					helperSize = {
// 						height: Math.round($(zoomtainer).height()/scaleFactor.y),
// 						width:	Math.round($(zoomtainer).width()/scaleFactor.x)
// 					};
// 					$(helper).css({width:helperSize.width+'px', height:helperSize.height+'px'});
// 					maxH =	$(global).height()-$(helper).height();
// 					maxW =	$(global).width()-$(helper).width();
// 					helperHalf = {width: ($(helper).width()/2), height: ($(helper).height()/2)};
// 					$(zoomed).css({
// 						background:	'url('+this.src+') no-repeat 0 0 #fff'
// 					});
// 					$(shade).css({
// 						backgroundImage:	'none', 
// 						opacity: 			0.75, 
// 						filter:				'alpha(opacity=75)', 
// 						background:			'#ccc'
// 					});
// 					var us = {width: $(global).width(), height: $(global).height(), top: $(global).offset().top, left: $(global).offset().left}
// 					$(currentContainer).unbind().hover(function(){
// 						$(shade).fadeIn(200);
// 						$(helper).fadeIn(200);
// 						$(zoomed).fadeIn(200);
// 						if(settings.hideIt){
// 							$(zoomtainer).show()
// 						}
// 					},function(){
// 						$(shade).fadeOut(200);
// 						$(helper).fadeOut(200);
// 						$(zoomed).fadeOut(200);
// 						if(settings.hideIt){
// 							$(zoomtainer).hide()
// 						}
// 					}).mousemove(function(e){
// 						var us = {width: $(global).width(), height: $(global).height(), top: $(global).offset().top, left: $(global).offset().left}
// 						var top =	(e.pageY - us.top) - helperHalf.height;
// 						var left =	(e.pageX - us.left) - helperHalf.width;
// 						var nleft = left > maxW ? maxW : left < 0 ? 0 : left;
// 						var ntop = top > maxH ? maxH : top < 0 ? 0 : top;
// 						$(zoomed).css({
// 							backgroundPosition: '-'+(nleft*scaleFactor.x)+'px -'+(ntop*scaleFactor.y)+'px'
// 						})
// 						$(helper).css({
// 							top:	ntop,
// 							left:	nleft,
// 							backgroundPosition: '-'+(nleft+1)+'px -'+(ntop+1)+'px'
// 						});
// 					});
// 				};
// 				zoomedImg.src = settings.src;
// 			});
// 		}); 
// 	};
// });
// 
// $(document).ready(function() {
// 	$('#zoomImg').children('img').each(function(){
// 		var srcFile = $(this).attr('src').replace('.jpg','.large.jpg');
// 		$(this).imgZoom({container:'.ztBucket', src:srcFile, hideIt:true});
// 	});					   
// });



	
	

