$.fn.openCart = function(){
	m = $("<div></div>").css({
		height:'100%',
		width:'100%',
		position:'fixed',
		left:0,
		top:0,
		'z-index':999,
		opacity:0.75,
		'background-color':'#fff'
	}).addClass("sc_overlay");
	i=$('<iframe src="javascript:false;document.write(\'\');" class="jqm" style="position:absolute;"></iframe>').css({'background-color':'#fff',opacity:0.75});
	ie6=$.browser.msie&&($.browser.version == "6.0");
	
	if(ie6){
		
		i.prependTo('body');
		//m.appendTo('body');
	}
	else{
		m.prependTo('body');
	}
	
	$("#shoppingCart12").css("z-index", "1000").animate({
		top: "0px"
	}, 250, "swing").addClass("open");
	
	/*$("#contentArea").animate({
		opacity: .2
	})*/
	/*$('#mainNav').css("z-index","9");*/
}

$.fn.closeCart = function(){
	
	i.remove();
	m.remove();
	$("#shoppingCart12").animate({
		top: "-175px"
	}, 250, "swing", function(){
		$(this).css("z-index", "");
	}).removeClass("open");
	
	/*$("#contentArea").animate({
		opacity: 1
	})*/
	/*$('#mainNav').css("z-index","100");*/
}
	

$.fn.openSearchContext = function(){
	$("#searchContext ul").slideDown(function(){
		$(this).addClass("open")
	})
}
$.fn.closeSearchContext = function(){
	$("#searchContext ul").slideUp(function(){
		$(this).removeClass("open")
	})
}
$.fn.updateSearchContext = function(clicked){
	console.log()
}

$.fn.loadRecents = function(){
	var json = $.evalJSON($.cookie("pe-recent"));
	
	if(json != null){
		var html = new Array;
		for(x=0; x< json.length; x++){
			html.push("<li><p>"+ json[x].c +"</p><a href=\""+ json[x].l +"\">"+json[x].t+"</a></li>");
		}
		
		$("#fPages").html(html.join(""));
	
		//Commented By Chirag, Reskin CMS
		//This is for the recently viewed carousel on every page
		//$('#fPages').jcarousel({
		//	buttonPrevHTML: "<div id=\"prevLinks\">Previous</div>",
		//	buttonNextHTML: "<div id=\"nextLinks\">Previous</div>",
		//	scroll: 7,
		//	animation: 1500,
		//	easing: "swing"
	    //});
	} else {
		$('#fPages').hide();
	}
	
}

$.fn.addRecent = function(obj){
	
	var currentRecents = $.evalJSON($.cookie("pe-recent"));
	//this filters the array and tries to remove the current item if the link matches
	
	if(currentRecents != null){
		currentRecents = jQuery.grep(currentRecents, function(value){
			return value.l != obj.l;
		});
		var newItem = new Array;
		newItem.push(obj);
		var json = newItem.concat(currentRecents);
	
	} else {
		var newItem = new Array;
		newItem.push(obj);
		var json = newItem;
	}
	
	$.cookie("pe-recent", $.toJSON(json), { path: '/', expires: 10 });
}

/*For Press Filter*/
$.fn.openFilterContext = function(list) {
		list.slideDown(function(){
			list.addClass("open")
		})
}
$.fn.closeFilterContext = function(listItem) {
		listItem.slideUp(function(){
			listItem.removeClass("open");
		})
}

function mouseover_topnav(){
	if(!$(this).hasClass("currTab"))
		$(this).addClass("active");
	if($(this).children("div.mn-sub1").length > 0){
		// this opens a first level nav
		$(this).children("div.mn-sub1").show();	
		if($.browser.msie&&($.browser.version == "6.0"))
			$("div.mn-sub1").bbgiframe({opacity : true});
	}
	
	if($(this).children("div.mn-sub2").length > 0){
		//# > 15 
		if($(this).find("div.mn-sub2 ul li").length > 15){
			$(this).children("div.mn-sub2").addClass("twoCol");
		}
		//add MSF feature here by Hugh
		var ind1=0,ind2=0,msf=ind1-ind2;
		ind1=$(this).parent().children().index($(this))+1;
		if($(this).find("div.mn-sub2 ul li").length > 15){
			if($(this).find("div.mn-sub2 ul li").length % 2 > 0){
				ind2=($(this).find("div.mn-sub2 ul li").length+1) / 2;
			}
			else{
				ind2=$(this).find("div.mn-sub2 ul li").length / 2;
			}
		}
		else{
			ind2=$(this).find("div.mn-sub2 ul li").length;
		}
		msf=ind1-ind2;
		if(msf>0){
			$(this).children("div.mn-sub2").height(this.offsetTop+$(this).height()-4);
		}
		// this opens a second level nav
		$(this).children("div.mn-sub2").show();
		if($.browser.msie&&($.browser.version == "6.0"))
			$("div.mn-sub2").bbgiframe({opacity : true});
	}
}

function mouseout_topnav(){
	if(!$(this).hasClass("currTab"))
		$(this).removeClass("active");	
	if($(this).children("div.mn-sub1").length > 0){
		// this closes first level navs
		$(this).children("div.mn-sub1").hide();
	}
	
	if($(this).children("div.mn-sub2").length > 0){
		// this closes second level navs
		$(this).children("div.mn-sub2").hide();
	}
}


/*For Press Filter*/
$(document).ready(function(){
	/*HUGH added on Jan 22 for artf1056486*/
	if($(document).height()>$("body").height()){
		$("body").height($(document).height());
	}
	/*HUGH added on Jan 22 for artf1058563 */
	/*
		Event Manager This should just invoke functions, we should not put alot of logic here.
	*/	
	$("#scTab a").click(function(){
		if(!$("#shoppingCart12").hasClass("open")){		
			$(this).openCart();
		} else {
			$(this).closeCart();
		}
	})
	$("#scClose").click(function(){
		$(this).closeCart();
	})
	
	
	$("#searchContext").click(function(){
		if(!$("#searchContext ul").hasClass("open")){
			$(this).openSearchContext();
		} else {
			$(this).closeSearchContext();
		}
	})
	$("#searchContext label").click(function(){
		$("#searchContext span.searchText").html($(this).text())
	})
	
	
	$(".searchTerm").bind("click", function(){
		//save this string for later
		$(this).attr("default", $(this).val());
		$(this).val("")
	})
	$(".searchTerm").bind("blur", function(){
		// if the user deleted all the text in the box, restore the default value.
		if($(this).val() == ""){
			$(this).val($(this).attr("default"))
		}
	})
	/*Implementation for old search box UI*/
	$(".clearOnCLick").one("click", function(){
		//save this string for later
		$(this).attr("default", $(this).val());
		$(this).val("")
	})
	
	$(".clearOnCLick").bind("blur", function(){
		// if the user deleted all the text in the box, restore the default value.
		if($(this).val() == ""){
			$(this).val($(this).attr("default"))
		}
	})
	/*End, Implementation for old search box UI*/
	
	//Commented this as per Hugh's request - global nav not working on Google chrome issue 
	//load the recent page links at the bottom of each page
	//$(this).loadRecents()
	
	
	// this checks to see if the element you hovered over has a subnav, then hides or shows it.
	$("#mainNav li").hoverIntent({
		interval: 100,	
		timeout: 100,
		over: mouseover_topnav, 
		out: mouseout_topnav
	})
	
	
	//$("button.btnSecondary41").after($("<span class='btnRightDark1'></span>"))
	
	//$("<span class='btnRightDark'></span>").appendTo($("button.btnSecondary41")).parent()
	
	
	//Begin, Section Commented By Chirag, For Reskin CMS, THE SECTION IS GIVING JAVASCRIPT ERROR ON THE PAGE
	/*KULDIP: Add code for featured and All Promotions Carousel Implementation */
	/*$('#featuredPromotions').jcarousel({
		buttonPrevHTML: "<div id=\"previousLinks\">Previous</div>",
		buttonNextHTML: "<div id=\"nextsLinks\">next</div>",
		scroll: 3,
		animation: 1300,
		easing: "swing"
	});*/
	
	/*$('#allPromotions').jcarousel({
		buttonPrevHTML: "<div id=\"previousLinks\">Previous</div>",
		buttonNextHTML: "<div id=\"nextsLinks\">next</div>",
		scroll: 1,
		animation: 1300,
		easing: "swing"
	});*/
	/*
	DEVELOPMENT CODE, DELETE BEFORE RELEASE
	
	$("#writeCookie").click(function(){
		
		var rand = Math.floor(Math.random()*1111);
		$(this).addRecent({
			t:'Page Title' + rand,
			c:'Category Title' + rand, 
			l:'link' + rand + '.html'
		});
		
		return false;
	})
	
	$("#readCookie").click(function(){
		alert($.evalJSON($.cookie("pe-recent")))
		return false;
	})
	
	$("#clearCookie").click(function(){
		$.cookie("pe-recent", null, { path: '/', expires: 10 });
		return false;
	})
	 END DEVELOPMENT CODE */
	//End, Section Commented By Chirag, For Reskin CMS, THE SECTION IS GIVING JAVASCRIPT ERROR ON THE PAGE
	
})	
if($.browser.safari){
		$("select.select").removeClass("select").css({"margin-right":"5px"});
		$("#mainSearch #searchContextNew .searchText").removeClass("searchText")
			.css({
				"font-size":"11px",
				"width":"150px"
			});
	}
