function init(screen){
var page=$("body").attr("class");
if(screen=="CTGY"){
	$(".subcatGrid").not(".stay-open").each(function(){if($(this).children(".gridItem:gt(7)").length>0){$(this).children(".gridItem:gt(7)").hide();$(this).append('<a class="seeAllSubs">See All '+$(this).children("h2").text()+'</a>');}});
	$(".seeAllSubs").click(function(){
		$(this).siblings(".gridItem:gt(7)").fadeIn();
		$(this).fadeOut();
	});
	$("#showDescription").click(function(){$("#description").dialog({width:700,height:400,modal:true});});
	$("#listView").click(function(){$("#listView").addClass("active");$("#gridView").removeClass("active");$(".productGrid").fadeTo(500,0.01,function(){$(".productGrid").addClass("productList list").removeClass("productGrid").removeClass("grid").fadeTo(500,1.0);});createCookie("Layout","List",30);return false;})
	$("#gridView").click(function(){$("#gridView").addClass("active");$("#listView").removeClass("active");$(".productList").fadeTo(500,0.01,function(){$(".productList").addClass("productGrid grid").removeClass("productList").removeClass("list").fadeTo(500,1.0);});createCookie("Layout","Grid",30);return false;})
	if($(".Book-Display #description > .sticky").length>0){
		$(".Book-Display #description > *").not(".Book-Display #description > .sticky").hide();
		$(".Book-Display #description").append('<span class="more">More...</span>');
		$(".Book-Display #description .more").click(function(){
			$(this).siblings("*").not(".sticky").fadeIn();
			$(this).fadeOut();
		});
	}
	if($(".Product-Secondary-Category #sticky_description > .sticky").length>0){
		$(".Product-Secondary-Category #sticky_description > *").not(".Product-Secondary-Category #sticky_description > .sticky").hide();
		$(".Product-Secondary-Category #sticky_description").append('<span class="more">...See More</span>');
		$(".Product-Secondary-Category #sticky_description .more").click(function(){
			$(this).siblings("*").not(".sticky").fadeIn();
			$(this).fadeOut();
		});
	}
}
if(screen=="SFNT"){
	
}
if(screen=="PROD"){
	$("#product-tabs").tabs();
	if($("#thumb-scroll img").length>3){
	$(".images").append('<img src="/common/css/PTC/sgraphics/left.png" id="thumb-scroll-left" class="scroll" />');
	$(".images").append('<img src="/common/css/PTC/sgraphics/right.png" id="thumb-scroll-right" class="scroll" />');
	}
	if($("#related-scroll .relatedProduct").length>2){
	$("#related-scroll").before('<img src="/common/css/PTC/sgraphics/up.png" id="related-scroll-up" class="scroll" />');
	$("#related-scroll").after('<img src="/common/css/PTC/sgraphics/down.png" id="related-scroll-down" class="scroll" />');
	}
	if($("#alsobought-scroll .relatedProduct").length>2){
	$("#alsobought-scroll").before('<img src="/common/css/PTC/sgraphics/up.png" id="alsobought-scroll-up" class="scroll" />');
	$("#alsobought-scroll").after('<img src="/common/css/PTC/sgraphics/down.png" id="alsobought-scroll-down" class="scroll" />');
	}
	$(".PROD .buyit .attribute #Font-Color .option, .PROD .buyit .attribute #Thread_Color .option, .PROD .buyit .attribute #Thread-Color .option, .PROD .buyit .attribute #Material .option, .PROD .buyit .attribute #Color .option, .PROD .buyit .attribute #Sticker-Solid .option, .PROD .buyit .attribute #Letter-Color .option").addClass("color-swatch");
	$(".PROD .buyit .attribute .color-swatch input:checked").parent().addClass("color-swatch-selected");
	$(".PROD .buyit .attribute .color-swatch").click(function(){
		$(this).parent().children(".color-swatch").removeClass("color-swatch-selected").children("input").removeAttr('checked');
		$(this).addClass("color-swatch-selected");
		$(this).children("input").attr('checked', 'checked');
	});
}

//modified to limit to five per category
$.widget( "custom.catcomplete", $.ui.autocomplete, {
		_renderMenu: function( ul, items ) {
			var self = this,
				currentCategory = "";
			var i = 0; //counter for categories
			$.each( items, function( index, item ) {
				if ( item.category != currentCategory ) {
					ul.append( "<li class='ui-autocomplete-category'>" + item.category + "</li>" );
					currentCategory = item.category;
					i = 0; //reset counter for next category
				}
				if(i++<5) //check and increment counter
					self._renderItem( ul, item );
			});
		}
});
$( "#searchText" ).catcomplete({
			source: "search.php",
			minLength: 2,
			select: function( event, ui ) {
				window.location.href=ui.item.path;
			}

});
$(".scroll").mouseenter(function(){
		var temp=$(this).attr("id");
		scrollee=temp.substring(0,temp.lastIndexOf("-"));
		direction=temp.substring(temp.lastIndexOf("-")+1);
		scrolling=setInterval('scroll("'+scrollee+'","'+direction+'")',15)
});
$(".scroll").each(function(){
		var temp=$(this).attr("id");
		scrollee=temp.substring(0,temp.lastIndexOf("-"));
		$("#"+scrollee).css({"overflow":"hidden"});
});

$(".scroll").mouseleave(function(){
	clearInterval(scrolling);
});

if (navigator.appName!='Microsoft Internet Explorer'){
$("#navigation .title,#navigation li").click(function(){$(this).trigger('click')});
}
$("#cartButton").mouseenter(function(){$("#MCRT").clearQueue().fadeIn();loadShipCalc();}).mouseleave(function(){$("#MCRT").delay(200).fadeOut();})
$("#MCRT").mouseenter(function(){$("#MCRT").clearQueue().fadeTo("slow",1.0);}).mouseleave(function(){$("#MCRT").clearQueue().delay(200).fadeOut();})

$("#shop-by-brand").mouseenter(function(){$("#SBB").clearQueue().fadeIn();}).mouseleave(function(){$("#SBB").delay(200).fadeOut();})
$("#SBB").mouseenter(function(){$("#SBB").clearQueue().fadeTo("slow",1.0);}).mouseleave(function(){$("#SBB").clearQueue().delay(200).fadeOut();})
$("#shop-by-character").mouseenter(function(){$("#SBC").clearQueue().fadeIn();}).mouseleave(function(){$("#SBC").delay(200).fadeOut();})
$("#SBC").mouseenter(function(){$("#SBC").clearQueue().fadeTo("slow",1.0);}).mouseleave(function(){$("#SBC").clearQueue().delay(200).fadeOut();})
$("#tips-info").mouseenter(function(){$("#TI").clearQueue().fadeIn();}).mouseleave(function(){$("#TI").delay(200).fadeOut();})
$("#TI").mouseenter(function(){$("#TI").clearQueue().fadeTo("slow",1.0);}).mouseleave(function(){$("#TI").clearQueue().delay(200).fadeOut();})
$("#specialty-shops").mouseenter(function(){$("#SS").clearQueue().fadeIn();}).mouseleave(function(){$("#SS").delay(200).fadeOut();})
$("#SS").mouseenter(function(){$("#SS").clearQueue().fadeTo("slow",1.0);}).mouseleave(function(){$("#SS").clearQueue().delay(200).fadeOut();})

}

function openReviews(){
	$("#review-tab-button").click();
	$("html,body").animate({"scrollTop":500},1000);
}

function scroll(scrollee,direction){
	if(direction=="up"){
		$("#"+scrollee).scrollTop($("#"+scrollee).scrollTop()-2);
	}else if(direction=="down"){
		$("#"+scrollee).scrollTop($("#"+scrollee).scrollTop()+2);
	}else if(direction=="left"){
		$("#"+scrollee).scrollLeft($("#"+scrollee).scrollLeft()-2);
	}else if(direction=="right"){
		$("#"+scrollee).scrollLeft($("#"+scrollee).scrollLeft()+2);
	}
}
function loadShipCalc(){
	if($("#shipCalc").length==0){
	$("body").append("<div id='shipCalc' title='Shipping Estimator'><img src='/common/sgraphics/PTC/loading.gif' style='position:absolute;left:240px;top:150px;' /></div>");
	$.get("/PAGE/SHIPCALC.html", function(data){
		$("#shipCalc").html(data);
	});
	}
}
function openShipCalc(){
	if($("#shipCalc").length>0){
	$("#shipCalc").dialog({width:530,height:350,modal:true});
	}
	return false;
}

function updateShipCalc(){
	$("#shipCalcAjax").html("<img src='/common/sgraphics/PTC/loading.gif' style='position:absolute;left:200px;top:50px;' />");
	$.get("/PAGE/SHIPCALC.html&Action=NEW&TKShip=1&TK_ShipCountry="+$("#TK_ShipCountry").val()+"&TK_ShipZip="+$("#TK_ShipZip").val()+"&resultsOnly=1", function(data){
		$("#shipCalcAjax").html(data);
	});
	return false;
}


function sendEmail(code){
	$("body").append("<div id='sendEmail' title='Email A Friend'><img id='load' src='/common/sgraphics/PTC/loading.gif' style='position:absolute;left:240px;top:150px;' /></div>");
	$("#sendEmail").dialog({width:530,height:420,modal:true,buttons: { "Send": function() {
		$("#sendEmail #data").hide();
		$("#sendEmail #load").show();
		$.get("http://www.pottytrainingconcepts.com/mm5/merchant.mvc?Method=JQuery&"+$("#sendEmail form").serialize(),function(data){
		if($.trim(data)=="Successfully Sent Email"){
			$(this).dialog("close");
			$("#sendEmail").remove();
			$(".ui-dialog, .ui-widget-overlay").remove();
		}else{
			$("#sendEmail #data").show();
			$("#sendEmail #load").hide();
		}
		}); 
	},"Cancel": function() { $(this).dialog("close");$("#sendEmail").remove();$(".ui-dialog, .ui-widget-overlay").remove(); } },
	close: function(event, ui) { $("#sendEmail").remove();$(".ui-dialog, .ui-widget-overlay").remove(); }});
	$.get("/PAGE/Tell.html&Product_Code="+code, function(data){
		$("#sendEmail").append("<div id='data'>"+data+"</div>");
		$("#sendEmail #load").hide();
		$("#sendEmail #emailTitle,#sendEmail #emailSubmit").hide();
	});

}
function postReview(code){
	$("html,body").animate({"scrollTop":100},1000,function(){
	var postReviewTitle="Add Product Review";
	if($("body").hasClass("Article-Display")){
		postReviewTitle="Add Comment"
	}
	$("body").append("<div id='postReview' title='"+postReviewTitle+"'><img id='load' src='/common/sgraphics/PTC/loading.gif' style='position:absolute;left:240px;top:150px;' /></div>");
	$("#postReview").dialog({width:530,height:490,modal:true,buttons: { "Submit": function() {
		$("#postReview #data").hide();
		$("#postReview #load").show();
		if($('#postReview input[name="review:title"]').val() && $('#postReview textarea').val() && $('#postReview input[name="review:name"]').val()  && $('#postReview input[name="review:email"]').val()){
			$("#postReview form").submit();
		}else{
			$("#postReview #data").show();
			$("#postReview #load").hide();
		} 
	},"Cancel": function() { $("#postReview").dialog("close");$("#postReview").remove();$(".ui-dialog, .ui-widget-overlay").remove(); } },
	close: function(event, ui) { $("#postReview").remove();$(".ui-dialog, .ui-widget-overlay").remove(); }});
	$.get("/"+code+"/WriteReview.html", function(data){
		if($("#postReview #data").length<1){
			$("#postReview").append("<div id='data'>"+data+"</div>");
		}
		$("#postReview #load").hide();
		$("#postReview #postReviewSubmit").hide();
	});
	});
}


function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function toggleShipping(){
	var s='hidden';
	if($('.customer .customer-ship h2 input').attr('checked')!=1)
		s='visible';
	$('.customer .customer-ship').children(':not(\'h2\')').each(function(){
		$(this).css('visibility',s);
	});
}
