var Sears = {
	topNav: function(){
		var global = this;
		var depts = $s('#deptNav')
		var shopAll = $s('#MNshopAll');
		var timer = 0;
		var timer2 = 0;
		var timer3 = 0;
		var timer4 = 0;
		var timer5 = 0;
		var idx = 0;
		var buffer = 0;
		if($s('body').is('#home')){
			depts.show();
		}else{
			depts.appendTo('body').css({
				top:  shopAll.offset().top + shopAll.height(),
				left: shopAll.offset().left
			});	
		}
		function loadFly(){
			$s('#tempNav').remove();
			depts.find('li.active').removeClass('active');
			depts.find('li#'+idx).addClass('active');
			var div = $s('<div/>').attr({id:'tempNav'}).css({
					position:'absolute',
					display:'none',
					float:'left',
					top:(depts.offset().top-22),
					left:(depts.offset().left+depts.width())-buffer,
					zIndex:1000
				}).appendTo('body').hover(function(){
					clearTimeout(timer2);
					clearTimeout(timer4);
					clearTimeout(timer5);
				},function(){
					timer2 = setTimeout(function(){
						$s('#tempNav').fadeOut(300,function(){$s(this).remove()});
						if($s('body').is(':not(#home)')){
							depts.fadeOut(300).find('li.active').removeClass('active');
						}else{
							depts.find('li.active').removeClass('active');
						}
					},800);	
				});
			div.append($s('#'+idx.split('_n')[0]+'_fly').clone()).show(10,function(){
				//alert($s('#tempNav').attr('id'));
				var _this = $s('#tempNav');
				_this.bgIframe();
				var tallest = _this.find('.col:eq(0)').height();
				_this.find('.col').each(function(i){
					if($s(this).height() > tallest){
						tallest = $s(this).height();
					}
				});
				_this.find('.col').height(tallest);
			});							   
		}
		shopAll.hover(function(){
			timer3 = setTimeout(function(){
				depts.fadeIn(300);							
			},500)				   
		},function(){
			clearTimeout(timer3);
			timer4 = setTimeout(function(){
				if($s('body').is('#home')){
					$s('#tempNav').fadeOut(300).find('li.active').removeClass('active');
				}else{
					depts.add('#tempNav').fadeOut(300).find('li.active').removeClass('active');
				}
			},500);
		}).click(function(){return false;});
		depts.children().hover(function(){
			clearTimeout(timer4)
			idx = $s(this).attr('id');
			$s(this).addClass('hover');
			var tempNav = $s('#tempNav');
			timer = setTimeout(loadFly,400);	
		},function(){
			$s(this).removeClass('hover');
			clearTimeout(timer);
		});
		depts.hover(function(){
			clearTimeout(timer2);
		},function(){
			$s('#tempNav').mouseout();
			timer5 = setTimeout(function(){
				$s('#tempNav').fadeOut(300,function(){$s(this).remove()});
				if($s('body').is(':not(#home)')){
					depts.fadeOut(300).find('li.active').removeClass('active');
				}else{
					depts.find('li.active').removeClass('active');
				}
			},500);
		});
		$s('input.srch').attr({disabled:'disabled'});
		$s('#keyword').css({color:'#666666'}).val('What are you shopping for?').focus(function(){
			$s('input.srch').removeAttr('disabled');
			$s(this).css({color:'#000000'});
			if(this.value == 'What are you shopping for?'){
				this.value = '';
			}else{
				$s(this).select();
				
			}	 
		}).blur(function(){
			if(this.value == ''){
				$s(this).css({color:'#666666'}).val('What are you shopping for?');
				$s('input.srch').attr({disabled:'disabled'});
			}else{
				$s('input.srch').removeAttr('disabled');
			}	
		});
		
	},
	getWindowSize : function(){
		var xScroll, yScroll, windowWidth, windowHeight;
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = document.body.scrollWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { 
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		if (self.innerHeight) {	
			windowWidth = self.innerWidth;
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { 
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { 
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}
		if(xScroll < windowWidth){	
			pageWidth = windowWidth;
		} else {
			pageWidth = xScroll;
		}
		return {'pageWidth':pageWidth, 'pageHeight':pageHeight, 'windowWidth':windowWidth, 'windowHeight':windowHeight};
	},
	/**
	 * 
	 */
	showHideRecentlyView: function(e){
		if(e)
			$s("#recentlyView").fadeIn("slow");
		else 
			$s("#recentlyView").fadeOut("slow");
	},
	preloadImages : function(){
		if(document.images){
			document.myImages = new Array();
			for (var i = 0; i < preloadImages.arguments.length; i++){
				document.myImages[i] = new Image;
				document.myImages[i].src = preloadImages.arguments[i];
			}
		}
	}
};

(function($s){
$s.fn.bgIframe = $s.fn.bgiframe = function(s) {
	// This is only for IE6
	if ( $s.browser.msie && /6.0/.test(navigator.userAgent) ) {
		s = $s.extend({
			top     : 'auto', // auto == .currentStyle.borderTopWidth
			left    : 'auto', // auto == .currentStyle.borderLeftWidth
			width   : 'auto', // auto == offsetWidth
			height  : 'auto', // auto == offsetHeight
			opacity : true,
			src     : 'javascript:false;'
		}, s || {});
		var prop = function(n){return n&&n.constructor==Number?n+'px':n;},
		    html = '<iframe class="bgiframe"frameborder="0"tabindex="-1"src="'+s.src+'"'+
		               'style="display:block;position:absolute;z-index:-1;'+
			               (s.opacity !== false?'filter:Alpha(Opacity=\'0\');':'')+
					       'top:'+(s.top=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderTopWidth)||0)*-1)+\'px\')':prop(s.top))+';'+
					       'left:'+(s.left=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth)||0)*-1)+\'px\')':prop(s.left))+';'+
					       'width:'+(s.width=='auto'?'expression(this.parentNode.offsetWidth+\'px\')':prop(s.width))+';'+
					       'height:'+(s.height=='auto'?'expression(this.parentNode.offsetHeight+\'px\')':prop(s.height))+';'+
					'"/>';
		return this.each(function() {
			if ( $s('> iframe.bgiframe', this).length == 0 )
				this.insertBefore( document.createElement(html), this.firstChild );
		});
	}
	return this;
};
})(jQuery);