var Kmart = {
	topNav: function(){
		var global = this;
		var depts = $('#deptNav')
		var shopAll = $('#MNshopAll');
		var timer = 0;
		var timer2 = 0;
		var timer3 = 0;
		var timer4 = 0;
		var timer5 = 0;
		var idx = 0;
		var buffer = 0;
		if($('body').is('#home')){
			depts.show();
		}else{
			depts.appendTo('body').css({
				top:  shopAll.offset().top + shopAll.height(),
				left: shopAll.offset().left
			}).hide();	
		}
		function loadFly(){
			$('#tempNav').remove();
			depts.find('li.active').removeClass('active');
			depts.find('li#'+idx).addClass('active');
			var div = $('<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(){
						$('#tempNav').fadeOut(300,function(){$(this).remove()});
						if($('body').is(':not(#home)')){
							depts.fadeOut(300).find('li.active').removeClass('active');
						}else{
							depts.find('li.active').removeClass('active');
						}
					},800);	
				});
			div.append($('#'+idx.split('_n')[0]+'_fly').clone()).show(10,function(){
				//alert($('#tempNav').attr('id'));
				var _this = $('#tempNav');
				_this.bgIframe();
				var tallest = _this.find('.col:eq(0)').height();
				_this.find('.col').each(function(i){
					if($(this).height() > tallest){
						tallest = $(this).height();
					}
				});
				_this.find('.col').height(tallest);
			});							   
		}
		shopAll.hover(function(){
			timer3 = setTimeout(function(){
				depts.fadeIn(300);							
			},500)				   
		},function(){
			clearTimeout(timer3);
			timer4 = setTimeout(function(){
				if($('body').is('#home')){
					$('#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 = $(this).attr('id');
			$(this).addClass('hover');
			var tempNav = $('#tempNav');
			timer = setTimeout(loadFly,400);	
		},function(){
			$(this).removeClass('hover');
			clearTimeout(timer);
		});
		depts.hover(function(){
			clearTimeout(timer2);
		},function(){
			$('#tempNav').mouseout();
			timer5 = setTimeout(function(){
				$('#tempNav').fadeOut(300,function(){$(this).remove()});
				if($('body').is(':not(#home)')){
					depts.fadeOut(300).find('li.active').removeClass('active');
				}else{
					depts.find('li.active').removeClass('active');
				}
			},500);
		});
		$('input#gobtn').attr({disabled:'disabled'});
		function qsval(name){
		  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
		  var results = new RegExp( "[\\?&]"+name+"=([^&#]*)" ).exec( window.location.href );
		  if( results == null ){
		    return "";
		  }else{
		    return results[1].replace(/[+]/g," ");
		  }
		}
		$('#keyword').css({color:'#666666'}).val(qsval('keyword')).focus(function(){
			$('input#gobtn').removeAttr('disabled');
			$(this).css({color:'#000000'});
			if(this.value == ''){
				this.value = '';
			}else{
				$(this).select();
				
			}	 
		}).blur(function(){
			if(this.value == ''){
				$(this).css({color:'#666666'}).val('');
				$('input#gobtn').attr({disabled:'disabled'});
			}else{
				$('input#gobtn').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)
			$("#recentlyView").fadeIn("slow");
		else 
			$("#recentlyView").fadeOut("slow");
	},
	dims : function(){
		return {
					v:window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight,
					h:window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth,
					vs:document.documentElement.scrollTop || document.body.scrollTop,
					hs:document.documentElement.scrollLeft || document.body.scrollLeft
			}
	}
}


//Ajax call
var httpRequestSupported = true;

function ajaxCall(url,callbackFunction,returnData,linkId) 
{ 
    var httpRequest = false; 

    // Exit if this function is not supported
    if (!httpRequestSupported) {
        return;  
    }
    
    // check if supported
    httpRequest = isHttpRequestSupported();
    
    if (!httpRequest) { 
        httpRequestSupported = false;
        return false; 
    } 
   
    // Map the response to the callback function
    httpRequest.onreadystatechange = function() { 
        if (httpRequest.readyState == 4) {  
            if (httpRequest.status == 200) {
                if (returnData) { 
                    eval(callbackFunction + '(httpRequest.responseXML,linkId)'); 
                } else { 
                    eval(callbackFunction + '(httpRequest.responseText,linkId)'); 
                }  
            } else { 
                // TODO:  Keep this line commented in production.  The user will have no idea what this means.
                //('The AJAX request was made to our backend server and the following error occurred: ' + httpRequest.status); 
                eval(callbackFunction + '("")'); 
            } 
        }
        else{
            if(callbackFunction == 'displayTabContent'){
                
                htmlValue = "<img src= '"+ imagePath + "img/backgrounds/loading.gif' />";
                document.getElementById(linkId).innerHTML = htmlValue;
            }
            if(callbackFunction == 'browseSpecialOffer'){   
                htmlValue = "<img src= '"+ imagePath + "img/backgrounds/loading.gif' />";
                linkId.innerHTML = htmlValue;           
            }
        } 
    } 
    
    httpRequest.open('GET', url, true); 
    httpRequest.send(null); 
}
function isHttpRequestSupported() {

    if (window.XMLHttpRequest) {   
        // Test if the Gecko engine is running.  Gecko supports AJAX
        httpRequest = new XMLHttpRequest(); 
        if (httpRequest.overrideMimeType) { 
            httpRequest.overrideMimeType('text/xml'); 
        }  
    } else if (window.ActiveXObject) { 
        // Test if an IE engine is running
        try {      
            httpRequest = new ActiveXObject("Msxml2.XMLHTTP"); 
        } catch (e) { 
            try {  
                httpRequest = new ActiveXObject("Microsoft.XMLHTTP"); 
            } catch (e) {} 
        } 
    } 
     
    if (!httpRequest) { 
        httpRequestSupported = false;
    } 
    return httpRequest;
}
function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}
function trimStr( value ) {
	
	return LTrim(RTrim(value));
	
}
function setStoreId(storeIdValue){
    storeId = storeIdValue;
}
(function($){
$.fn.bgIframe = $.fn.bgiframe = function(s) {
	// This is only for IE6
	if ( $.browser.msie && /6.0/.test(navigator.userAgent) ) {
		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 ( $('> iframe.bgiframe', this).length == 0 )
				this.insertBefore( document.createElement(html), this.firstChild );
		});
	}
	return this;
};
})(jQuery);





