$(document).ready(function(){
	
	//Remove old logo row
	$("#logo-bg").parent().remove();
	//Remove old search bar
	$(".wba_maintable").children().children("tr:first").remove();
	//Remove old footer
	$(".copyright").parent().parent().remove();
	
	pageDirector();
	
	$("#frame-3_s").hide();
	$("body").show();
});

function pageDirector() {
	// Run different scripts to format different pages
	//alert(window.location.href.split("?")[0]);
	var thisPage = location.href.substring((location.href.lastIndexOf("/"))+1),
		url = window.location.href.split("?")[0],
		thisURL = url.split("/"),
		thisSubPage = thisURL[3].substring(0,6);
		//alert(thisSubPage);
	// Scripts to pull out content from tables
	switch(thisSubPage) {	
		case "":
			home();
			break;
		case "catego":
			var cat = thisURL[6].split(".");
			var cat = cat[0];
			var catid = thisURL[4];
			
			category(cat);

			switch(cat) {
			   case "VH1-Classic-Records":
			    insertImage("vh_vh1classicrecords_showpageheader_596x105.jpg", cat);
			    break;
				 case "Anvil-The-Story-of-Anvil":
			    insertImage("vh1_anvil_showpageheader_596x105.jpg", cat);
			    break;
				 case "Celebrity-Rehab":
			    insertImage("vh1_celebrehab_showpageheader_596x105.jpg", cat);
			    break;
				 case "Flavor-of-Love":
			    insertImage("vh1_flavoroflove_showpageheader_596x105.jpg", cat);
			    break;
				 case "I-Love-New-York":
			    insertImage("vh1_iloveny_showpageheader_596x105.jpg", cat);
			    break;
				 case "I-Love-the-70s-80s-and":
			    insertImage("vh1_ilovethe70s80s90s_showpageheader_596x105.jpg", cat);
			    break;
				 case "Kissology":
			    insertImage("vh1_kissology_showpageheader_596x105.jpg", cat);
			    break;
				 case "Mob-Wives":
			    insertImage("vh1_mobwives_showpageheader_596x105.jpg", cat);
			    break;
				 case "My-Big-Friggin-Wedding":
			    insertImage("vh1_mybigfrigginwedding_showpageheader_596x105.jpg", cat);
			    break;
				 case "Rock-Docs":
			    insertImage("vh_rockdocs_showpageheader_596x105.jpg", cat);
			    break;
				 case "Rock-of-Love":
			    insertImage("vh1_rockoflove_showpageheader_596x105.jpg", cat);
			    break;
				 case "Storytellers":
			    insertImage("vh1_storytellers_showpageheader_596x105.jpg", cat);
			    break;
				 case "That-Metal-Show":
			    insertImage("vh1_thatmetalshow_showpageheader_596x105.jpg", cat);
			    break;
				 case "Tough-Love":
			    insertImage("vh1_toughlove_showpageheader_596x105.jpg", cat);
			    break;
				  case "VH1-Classic":
				 //insertImage("mtvjackass_logo_596x105.gif", cat);
				 specialCat('vh1classic');
			    break;
}
			break;
		case "search":
			search();
			break;
		case "cart.h":
			cart();
			//Move shipping info into correct place - for holidays 2011
			if ($("div.cartWrapper").length > 0) {
				$("div.cartWrapper").prepend($("div.holidayShippingInfo"));
			}
			break;
		case "myAcco":
			myAccount();
			break;
		case "orderC":
			orderConfirmation();
			break;
		case "orderS":
			orderStatus();
			break;
		case "conten":
			if (thisURL[4]) {
				var url = thisURL[4].substring(0,4);
				if (url == 'Help') 
					help();
				else 
					if (thisURL[4] == 'Shows.htm') 
						portal();
				else 
					if (thisURL[4] == 'Apparel.htm') {
						portal();
					}
				else 
					portal(thisURL[4]);  
			}
			break;
		default: 
			details();
			break;	
	}
	
	/*Header dropdowns*/
	
	//Move Left
	$("#nav2").css({"marginLeft":"-5px"});
	//Make list carry to next column after certain # of <li>'s
	$(".dropdownlist").each(function(i) {
		$(this).children("li:nth-child(14n)").addClass("lastinlist");
		var last = $(this).children("li.lastinlist");
		var lastcount = $(this).children("li.lastinlist").size(); 
		
		if (lastcount == 0)
			$(this).css("width", "290px");
		else if (lastcount == 1)
			$(this).css("width", "580px");
		else if (lastcount == 1)
			$(this).css("width", "870px");
	});
		
	/* Footer */
	$(".footerGrayRight").css("margin", "0px");
	
	/* Breadcrumb */
	$(".crumbHome").parent().children().wrapAll("<div class='thirtythree breadcrumbWrapper'></div>");
	$(".content").prepend($(".breadcrumbWrapper"));
	$("<span>></span>").insertAfter($(".breadcrumbWrapper img"));
	$("[src*='orange_closed.gif']").remove();
	//Remove from some pages (search)
	$(".searchHeader").prev($(".breadcrumbWrapper")).remove();
	//Relink portals
	$("a.crumbPast:contains('Shows')").attr("href", "/content/Shows.htm");
	$("a.crumbPast:contains('Apparel')").attr("href", "/content/Apparel.htm");
	
	//Just Title pages
	if (thisSubPage == 'orderS' || thisSubPage == 'myAcco' || thisSubPage == 'orderC') {
		var header = $(".breadcrumbWrapper span.crumbPast:last").html();
		$(".breadcrumbWrapper").html(header).css("margin", "10px");
	}
	else if (thisSubPage == 'conten' && thisURL[4] == 'Help.htm') {
		var header = $(".breadcrumbWrapper span.crumbPast:last").html();
		$(".breadcrumbWrapper").html(header).css("margin", "10px");
	}
	
	//Remove Product Title
	$("#crumbProductTitle").parent().remove();
	
	
	/* Main Content */
	
	//Button Styling - change all small add to cart buttons to Add to Cart text link
	$(".wba_add_to_cart_btn, .preorder_btn").parent().html("Add to Cart");
		
	//Link Coloring
	$(".thirtynine a, .forty a").css({"color":"#2a2a2a"});
	$(".catLeftNav .leftnav a, .detailsLeftNav .leftnav a").css("color", "#1192ff");
	
	/* Widgets */
	
	//Headers
	$(".product-widget-label, .product-widget-label-leftnav").css({"padding":"0px", "fontSize":"27px"});
	
	$(".product-widget-label, .product-widget-label-leftnav").each(function(i) {
		var title = $(this).children("b").text();
		$(this).html("<h2><span>" + title + "</span></h2>");
		$(this).children("b").remove();
	});
	
	/* Home Featured Products - Img size 124x124, What's New/Top Shows - Img size 100x100 */
	$("#content-4").children().children().addClass("eighteen showsLatestProductWrapper");
	$("#content-5").children().children().addClass("eighteen showsBestSellerWrapper");
	$("#content-6").children().children().addClass("eighteen featuredProductWrapper");
	$("#content-7").children().children().addClass("eighteen whatsNewWrapper");
	$("#content-8").children().children().addClass("eighteen topShowsWrapper");
	$("#frame-6_s").children().children().addClass("eighteen recentlyViewedWrapper");
	
	
	//use numbers to move things so this can be resused
	$(".eighteen").children("table").children().children().children().children("a").children("img").parent().wrap("<div class='nineteen fpImageWrapper'></div>");
	$(".nineteen").wrap("<div class='twenty fpProductWrapper'></div>");

	//Wrap and Move associated product elements
	j = 0;
	k = 0;
	l = 0;
	m = 0;
	$(".twenty").each(function(i) {
		if ($(this).parent().parent().parent().parent().prev().children().children("span").length == 0) {
			/*if (m == 3) 
				m = 0;
			//wrap title, price, add to cart
			alert($(this).parent().parent().next().children().eq(m).children().children("a").text());
			$(this).parent().parent().next().children().eq(m).children().children("a").wrap("<div class='twentyone fpTitleWrapper'></div>");
			var title = $(this).parent().parent().next().children().eq(m).children().children("div");
			$(this).append($(title));
			$(this).parent().parent().next().next().children().eq(m).children().children().wrap("<div class='twentytwo fpPriceWrapper'></div>");
			
				
			m = m + 1;*/
			if (j == 4) 
				j = 0;
			//wrap title, price, add to cart
			$(this).parent().next().children("a").wrap("<div class='twentyone fpTitleWrapper'></div>");
			
			$(this).parent().parent().next().next().children().eq(j).children().children().children().children().children("span").wrap("<div class='twentytwo fpPriceWrapper'></div>");
			//append add to cart to price
			var price = $(this).parent().parent().next().next().children().eq(j).children().children().children().children().children("div");
			if ($(this).parent().parent().next().next().children().eq(j).children().children().children().children().children("a").text() == 'more info')
				$(this).parent().parent().next().next().children().eq(j).children().children().children().children().children("a").text("Add to Cart");
			$(price).append($(this).parent().parent().next().next().children().eq(j).children().children().children().children().children("a"));
			
			//alert($(price).html());
			//move title, price, add to cart
			$(this).append($(this).parent().next().children("div.twentyone"));
			$(this).append($(price));
			//move product divs out of table
			var container = $(this).parent().parent().parent().parent().parent();
			$(container).append($(this));
			//Check for empty price wrapper
			if ($(this).children(".twentytwo").children("span.bold-price").html() == '') 
				$(this).children(".twentytwo").children("span.bold-price").remove();
			
			j = j + 1;
		}
		else {
			//Portal widgets
			if ($(this).parent().parent().parent().parent().prev().children().children("span").text() == 'VH1 Classic Shows Best Sellers' || $(this).parent().parent().parent().parent().prev().children().children("span").text() == 'VH1 Classic Apparel Best Sellers') {
				if (k == 4) 
					k = 0;
				
				//wrap title, price, add to cart
				$(this).parent().next().children("a").wrap("<div class='twentyone fpTitleWrapper'></div>");
				
				$(this).parent().parent().next().next().children().eq(k).children().children().children().children().children("span").wrap("<div class='twentytwo fpPriceWrapper'></div>");
				//append add to cart to price
				var price = $(this).parent().parent().next().next().children().eq(k).children().children().children().children().children("div");
				if ($(this).parent().parent().next().next().children().eq(k).children().children().children().children().children("a").text() == 'more info')
					$(this).parent().parent().next().next().children().eq(k).children().children().children().children().children("a").text("Add to Cart");
				$(price).append($(this).parent().parent().next().next().children().eq(k).children().children().children().children().children("a"));
				k = k + 1;
			}
			//Recently viewed
			else if ($(this).parent().parent().parent().parent().prev().children().children("span").text() == 'Items Recently Viewed') {
					//wrap title, price, add to cart
					$(this).parent().next().children("a").wrap("<div class='twentyone fpTitleWrapper'></div>");
					
					$(this).parent().parent().next().next().children().eq(l).children().children().children().children().children("span").wrap("<div class='twentytwo fpPriceWrapper'></div>");
					//append add to cart to price
					var price = $(this).parent().parent().next().next().children().eq(l).children().children().children().children().children("div");
					if ($(this).parent().parent().next().next().children().eq(l).children().children().children().children().children("a").text() == 'more info')
						$(this).parent().parent().next().next().children().eq(l).children().children().children().children().children("a").text("Add to Cart");
					$(price).append($(this).parent().parent().next().next().children().eq(l).children().children().children().children().children("a"));
					l = l + 1;
				}
			else {
				if (j == 4) 
					j = 0;
				
				//wrap title, price, add to cart
				$(this).parent().next().children("a").wrap("<div class='twentyone fpTitleWrapper'></div>");
				
				$(this).parent().parent().next().next().children().eq(j).children().children().children().children().children("span").wrap("<div class='twentytwo fpPriceWrapper'></div>");
				//append add to cart to price
				var price = $(this).parent().parent().next().next().children().eq(j).children().children().children().children().children("div");
				if ($(this).parent().parent().next().next().children().eq(j).children().children().children().children().children("a").text() == 'more info')
					$(this).parent().parent().next().next().children().eq(j).children().children().children().children().children("a").text("Add to Cart");
				$(price).append($(this).parent().parent().next().next().children().eq(j).children().children().children().children().children("a"));
				j = j + 1;
			}
			
			//alert($(price).html());
			//move title, price, add to cart
			$(this).append($(this).parent().next().children("div.twentyone"));
			$(this).append($(price));
			//move product divs out of table
			var container = $(this).parent().parent().parent().parent().parent();
			$(container).append($(this));
			//Check for empty price wrapper
			if ($(this).children(".twentytwo").children("span.bold-price").html() == '') 
				$(this).children(".twentytwo").children("span.bold-price").remove();
		}	
		i = i + 1;
	
	});
	
	//Styling
	//add margin on first, remove margin on last product
	$(".eighteen").each(function() {
		$(this).children(".twenty:first").css("marginLeft", "10px");
		$(this).children(".twenty").eq(4).css({"marginLeft":"10px", "clear":"both"});
		$(this).children(".twenty:last").css("marginRight", "0px");
	});
	
	$("#frame-6_s .eighteen").each(function() {
		$(this).children(".twenty:last").css({"marginLeft":"0px", "clear":"none"});
	});
	
	/* Right Widgets */
	
	/* Top Sellers Wide */
	
	$("#content-11").children().children().addClass("eighteen topSellerHomeWrapper");
	if (thisSubPage == "cart.h") {
		$("#content-2").children().children().wrapAll("<div class='eighteen topSellerNarrowWrapper'></div>");
	}
	else
		$("#content-2").children().children().addClass("eighteen topSellerNarrowWrapper");
	
	//use numbers to move things so this can be resused
	$("#content-11 .eighteen").children("table").children().children().children().children("a").children("img").parent().wrap("<div class='nineteen tshImageWrapper'></div>");
	$("#content-11 .nineteen").wrap("<div class='twenty tshProductWrapper'></div>");
	$("#content-2 .eighteen").children("table").children().children().children().children("a").children("img").parent().wrap("<div class='nineteen tsnImageWrapper'></div>");
	$("#content-2 .nineteen").wrap("<div class='twenty tsnProductWrapper'></div>");
	//Wrap and Move associated product elements

	$("#content-11 div.twenty, #content-2 div.twenty").each(function() {
		//wrap title, price, add to cart
		$(this).parent().next().children("a").wrap("<div class='twentyone tshTitleWrapper' style='margin-top:0px;'></div>");
		
		$(this).parent().parent().next().next().children().children().children().children().children().children("span").wrap("<div class='twentytwo tshPriceWrapper'></div>");
		//append add to cart to price
		var price = $(this).parent().parent().next().next().children().children().children().children().children().children("div");
		if ($(this).parent().parent().next().next().children().children().children().children().children().children("a").text() == 'more info')
			$(this).parent().parent().next().next().children().children().children().children().children().children("a").text("Add to Cart");
		$(price).append($(this).parent().parent().next().next().children().children().children().children().children().children("a"));
		//move title, price, add to cart
		$(this).append($(this).parent().next().children("div.twentyone"));
		$(this).append($(price));
		//move product divs out of table
		var container = $(this).parent().parent().parent().parent().parent();
		$(container).append($(this));
		//Check for empty price wrapper
		if ($(this).children(".twentytwo").children("span.bold-price").html() == '')
			$(this).children(".twentytwo").children("span.bold-price").remove();
		//Put title and price in own right wrapper
		$(this).children(".tshTitleWrapper").wrap("<div class='twentyfour tshRightWrapper'></div>");
		var rightwrapper = $(this).children(".twentyfour");
		$(rightwrapper).append($(this).children(".tshPriceWrapper"));
	});
	
	//remove bottom border for last item 
	$(".topSellerHomeWrapper, .topSellerNarrowWrapper").children(".twenty:last").css("border", "none");
	
	//Resize Images
	var fpimage = $("#content-6 div.nineteen").children("a").children("img");
	resizeImages(fpimage, 124, 124);
	var wnimage = $("#content-7 div.nineteen, #content-8 div.nineteen").children("a").children("img");
	resizeImages(wnimage, 100, 100);
	var tshimage = $("#content-11 div.nineteen").children("a").children("img");
	resizeImages(tshimage, 100, 100);
	var tsnimage = $("#content-2 div.nineteen, .thirtyone").children("a").children("img");
	resizeImages(tsnimage, 75, 75);
	var tsnimage = $("#content-4 div.nineteen").children("a").children("img");
	resizeImages(tsnimage, 130, 130);
	var tsnimage = $("#content-5 div.nineteen").children("a").children("img");
	resizeImages(tsnimage, 100, 100);
	var rvimage = $("#frame-6_s div.nineteen").children("a").children("img");
	resizeImages(rvimage, 100, 100);
	var catimage = $("div.thirtyfour").children("a").children("img");
	resizeImages(catimage, 110, 110);
	
	//Change image wrapper box size for 100x100 widgets
	$("#content-7 div.nineteen, #content-8 div.nineteen, #content-11 div.nineteen, #content-5 div.nineteen, #frame-6_s div.nineteen").addClass("twentythree");
	$("#content-2 div.nineteen").addClass("thirtyone");
	$("#content-4 div.nineteen").addClass("thirtytwo");
	$("div.thirtyfour").addClass("fortyone");
	$("#content-13 div.fifty").addClass("fortyseven");
	$("#content-14 div.fifty").addClass("fortyeight");
	
	//Add to cart links
	$(".twentytwo a:contains('Add to Cart')").each(function() {
		var link = $(this).parent().parent().children(".twentyone").children().attr("href");
		$(this).attr("href", link);
	});
	$("#content-14 .twentytwo a:contains('Add to Cart')").each(function() {
		var link = $(this).parent().parent().parent().children(".fifty").children().attr("href");
		$(this).attr("href", link);
	});
	
	//Truncate text
	//Best Sellers Narrow
	truncateText($("#content-2 .tshTitleWrapper a"), 30);
	//Category/Search Products
	truncateText($(".thirtysix  a"), 50);
	if (thisSubPage == 'search')
		truncateText($(".thirtysix  a"), 40);
	//Home Products
	truncateText($("#frame-6_s .fpTitleWrapper  a"), 65);
	//Recently Viewed
	truncateText($(".homeWrapper .fpTitleWrapper  a"), 65);
	//Portals
	truncateText($("#content-4 .fpTitleWrapper  a"), 55);
	truncateText($("#content-5 .fpTitleWrapper  a"), 55);
	//Boutique
	truncateText($("#content-14 .jsTitleWrapper a"), 55);
	
	//Hide Recently Viewed if no products
	if ($("#frame-6_s").children().children().children("table").is(":empty") || $("#frame-6_s .product-widget-label").length <= 0) {
		if (thisSubPage == 'conten' && thisURL[4] == 'Apparel.htm') {
			$(".content").css("height", "875px");
		}
		$("#frame-6_s").hide();
	}
	
	//Remove original tables, header
	$(".eighteen").children("table").remove();
	$("[src*='corner_']").remove();
	$("h1").hide();
	
	/* IE7 Fixes */
	if ($.browser.msie) {
		if ($.browser.version == '7.0') {
			//
		}
	}
	
	/* Safari Fixes */
	if ($.browser.safari) {
	  $(".detailsLeftNav").children("table:first").css("marginLeft", "-64px");
	}
	
	//Right Wrapper
	//$("#frame-2_s").wrap(("<div class='rightWrapper' style='float:left;'></div>"));
	$(".rightWrapper").append($("#content-10"));
	$(".rightWrapper").append($("#content-11"));
	$(".rightWrapper").append($("#frame-2_s"));
	$(".rightWrapper").append($("#frame-3_s"));
	$(".rightWrapper").append($("#frame-2"));
	
	/* Safari Fixes */
	if ($.browser.safari) {
	  $("#frame-2").css("top", "372px");
	  $("#frame-6_s").css({"clear":"both", "marginTop":"10px"});
	  $(".productDescriptionWrapper").css("clear", "both");
	  $("#content-12").css("marginBottom", "10px");
	}
	
	//Leftnav
	$(".leftnav-new-head").children().children().children().children("a").parent().css("width", "100px");
	
	//Hide Newsletters
	$("#frame-2_s, frame-3_s").hide();
	
	
	//New blue bars on image hover
	$(".nineteen, .thirtyfour").hover(
	  function () {
		$(this).append($("<div class='hoverBar'><img src='/images/vh1_hover_bar.jpg'></div>"));
		  }, 
	  function () {
	    $(this).find(".hoverBar").remove();
	  }
	);
	
	//Button hovers 
	$(".wba_search_btn").hover(
	  function () {
		$(this).attr("src", "/images/vh1_gohover_btn.jpg");
		  }, 
	  function () {
	   $(this).attr("src", "/images/vh1_go_btn.jpg");
	  }
	);

}

function home () {
	//Hide widgets
	$("#frame-3_s").css("display", "none");
	$("#frame-6_s").css("display", "none");
	
	//put marquee widget in wba_contentright
	$(".wba_contentright").prepend($("#content-18"));
	//remove br after it
	$(".wba_contentright").children("br").remove();
	//Create Home wrapper
	$("#content-18").wrap("<div class='homeWrapper'></div>");
	//Put widgets in wrapper
	$(".homeWrapper").append($("#content-5"));
	$(".homeWrapper").append($("#content-6"));
	$(".homeWrapper").append($("#content-7"));
	$(".homeWrapper").append($("#content-8"));
	$(".homeWrapper").append($("#content-10"));
	$(".homeWrapper").append($("#content-11"));
	//Remove table
	$(".homeWrapper").next("table").remove();
	
	//Right Wrapper
	$("<div class='homeRightWrapper' style='float:left;'></div>").insertAfter($(".homeWrapper"));
	$(".homeRightWrapper").append($("#content-10"));
	$(".homeRightWrapper").append($("#content-11"));
	$(".homeRightWrapper").append($("#frame-2_s"));
	//$(".homeRightWrapper, #content-7, #content-8").hide();
}


function portal(){
	//Hide widgets
	$("#frame-3_s").css("display", "block");
	$("#frame-2_s").css("display", "none");
	$("#content-1").css("display", "none");
	
	//Give Bottom shows widget new id so it does not take other properties
	$("#content-6").attr("id", "content-12");
	
	//Move widgets around
	//Left Wrapper
	$("#content-1").wrap("<div class='twentynine showsLeftWrapper'></div>");
	$(".twentynine").append($("#content-2"));
	//Center Wrapper
	$("#content-3").wrap("<div class='thirty showsCenterWrapper'></div>");
	$(".thirty").append($("#content-10"));
	$(".thirty").append($("#content-4"));
	$(".thirty").append($("#content-5"));
	$(".thirty").append($("#content-12"));
	
	$(".content").prepend($(".thirty"));
	$(".content").prepend($(".twentynine"));
	
	$("#content-5").css("height", "460px");
	
	//Add in title for all shows (this is dynamically set for other widgets)
	$("#content-12 span").text("All Shows");
	
	//Remove old table
	$(".showsCenterWrapper").next("table").children().children().children().children("table").remove();
	
	//Right Wrapper
	$("<div class='rightWrapper' style='float:left;'></div>").insertAfter($(".showsCenterWrapper"));
}

function category (page) {
	
	if (page == 'VH1-Classic') {
		$("#frame-3").attr("id", "specialCat-1").addClass("specialCatWidget");
		$("#frame-4").attr("id", "specialCat-2").addClass("specialCatWidget");
		$("#frame-5").attr("id", "specialCat-3").addClass("specialCatWidget");
		$("#frame-6").attr("id", "specialCat-4").addClass("specialCatWidget");
		
		$("#specialCat-1").children().children().addClass("eighteen specialCatWrapper");
		$("#specialCat-2").children().children().addClass("eighteen specialCatWrapper");
		$("#specialCat-3").children().children().addClass("eighteen specialCatWrapper");

		$("#specialCat-4").children().children().addClass("eighteen specialCatWrapper");
		
		
		//use numbers to move things so this can be resused
		$(".eighteen").children("table").children().children().children().children("a").children("img").parent().wrap("<div class='nineteen fpImageWrapper'></div>");
		$(".nineteen").wrap("<div class='twenty fpProductWrapper'></div>");
	
		//Wrap and Move associated product elements
		j = 0;
		
		$(".twenty").each(function(i) {
				if (j == 3) 
					j = 0;
				
				//wrap title, price, add to cart
				$(this).parent().next().children("a").wrap("<div class='twentyone fpTitleWrapper'></div>");
				
				$(this).parent().parent().next().next().children().eq(j).children().children().children().children().children("span").wrap("<div class='twentytwo fpPriceWrapper'></div>");
				//alert($(this).parent().parent().next().next().children().eq(j).children().children().children().children().children("span"));
				//append add to cart to price
				var price = $(this).parent().parent().next().next().children().eq(j).children().children().children().children().children("div");
				$(price).append($(this).parent().parent().next().next().children().eq(j).children().children().children().children().children("a"));
		
				//move title, price, add to cart
				$(this).append($(this).parent().next().children("div.twentyone"));
				$(this).append($(price));
				//move product divs out of table
				var container = $(this).parent().parent().parent().parent().parent();
				$(container).append($(this));
				//Check for empty price wrapper
				if ($(this).children(".twentytwo").children("span.bold-price").html() == '') 
					$(this).children(".twentytwo").children("span.bold-price").remove();

				j = j + 1;
		});
		
		//Styling
		//add margin on first, remove margin on last product
		$(".eighteen").each(function() {
			$(this).children(".twenty:first").css("marginLeft", "10px");
			$(this).children(".twenty").eq(4).css({"marginLeft":"10px", "clear":"both"});
			$(this).children(".twenty:last").css("marginRight", "0px");
		});
		
		
		var jackassimage = $("#specialCat-1 div.nineteen, #specialCat-2 div.nineteen, #specialCat-3 div.nineteen, #specialCat-4 div.nineteen").children("a").children("img");
		resizeImages(jackassimage, 110, 110);
		
		//Add to cart links
		$(".twentytwo a:contains('Add to Cart')").each(function() {
			var link = $(this).parent().parent().children(".twentyone").children().attr("href");
			$(this).attr("href", link);
		});
		$("#content-14 .twentytwo a:contains('Add to Cart')").each(function() {
			var link = $(this).parent().parent().parent().children(".fifty").children().attr("href");
			$(this).attr("href", link);
		});
		
		//Truncate text
		truncateText($(".twenty .fpTitleWrapper  a"), 55);

		//Remove original tables, header
		$("#specialCat-1 .eighteen, #specialCat-2 .eighteen, #specialCat-3 .eighteen, #specialCat-4 .eighteen").children("table").remove();
		$("[src*='corner_']").remove();
		$("h1").hide();	
	}
	
	//Hide widgets
	$("#frame-3_s").css({"display":"block"});
	
	$("#frame-2_s").css("display", "none");
	
	//Give widgets styling ids
	$("#cat_btm-1").attr("id", "content-1");
	$("#cat_btm-2").attr("id", "content-2");
	
	//Move widgets around
	//Left Wrapper
	$("#content-1").wrap("<div class='twentynine showsLeftWrapper'></div>");
	$(".twentynine").append($("#content-2"));
	$(".content").prepend($(".twentynine"));
	//Center Wrapper
	$("<div class='thirty catCenterWrapper'></div>").insertAfter($(".twentynine"));
	
	if ($.browser.safari) {
		//Right Wrapper
		$("<div class='catRightWrapper' style='float:left;'></div>").insertAfter($(".catCenterWrapper"));
		$(".catRightWrapper").append($("#frame-3_s"));
		$(".catRightWrapper").append($("#frame-2"));
		$("#frame-6_s").insertAfter($(".catRightWrapper"));
		$("#frame-6_s").css("clear", "both");
		$("#frame-2, #frame-3_s").css({"marginLeft":"10px"});
	}
	
	/*if (page == 'Jersey-Shore') {
		$("#title").parent().parent().parent().remove();
		$("#cat_btm-3").hide();
		$("#cat_btm-3").children().children().children().children().children().children().children("a").children("img").parent().wrap("<div class='thirtyfour catImageWrapper'></div>");
		$("#cat_btm-3 .thirtyfour").wrap("<div class='thirtyfive catProductWrapper'></div>");
		
		m = 0;
		$("#cat_btm-3 .thirtyfive").each(function(i){
			if (m == 3) 
				m = 0;
			
			//wrap title, price, add to cart
			$(this).parent().next().children("a").wrap("<div class='thirtysix catTitleWrapper'></div>");
			
			$(this).parent().parent().next().next().children().eq(m).children().children().children().children().children("span").wrap("<div class='thirtyseven catPriceWrapper'></div>");
			//append add to cart to price
			var price = $(this).parent().parent().next().next().children().eq(m).children().children().children().children().children("div");
			//alert($(this).parent().parent().next().next().children().eq(m).children().children().children().children().children("a").html());
			
			$(price).append($(this).parent().parent().next().next().children().eq(m).children().children().children().children().children("a"));
			
			//move title, price, add to cart
			$(this).append($(this).parent().next().children("div.thirtysix"));
			$(this).append($(price));
			//move product divs out of table
			$(".catCenterWrapper").append($(this));
			//Check for empty price wrapper
			
			if ($(this).children(".thirtyseven").children("span.bold-price").html() == '') 
				$(this).children(".thirtyseven").children("span.bold-price").remove();
			
			//hr
			if (m == 2 || m == 5) {
				$("<hr class='thirtyeight catHr'>").insertAfter($(this));
			}
			
			m = m + 1;
			
		});
		$(".thirtyseven").children("span").children("span").css({"border":"none", "paddingRight":"0px"});
	}
	else {*/
		$("td.y").children("a").children("img").parent().wrap("<div class='thirtyfour catImageWrapper'></div>");
		$(".thirtyfour").wrap("<div class='thirtyfive catProductWrapper'></div>");
		
		m = 0;
		$(".thirtyfive").each(function(i){
			if (m == 3) 
				m = 0;
			//wrap title, price, add to cart
			$(this).parent().parent().next().children().eq(m).children().children("a").wrap("<div class='thirtysix catTitleWrapper'></div>");
			var title = $(this).parent().parent().next().children().eq(m).children().children("div");
			$(this).append($(title));
			$(this).parent().parent().next().next().children().eq(m).children().wrap("<div class='thirtyseven catPriceWrapper'></div>");
			var price = $(this).parent().parent().next().next().children().eq(m).children("div");
			$(price).children().children("br").remove();
			$(this).append($(price));
			var price = $(this).children(".catPriceWrapper");
			//create Add to cart
			$(this).children(".catTitleWrapper").children("a").clone().appendTo($(price)).html("Add to Cart");
			
			//move product divs out of table
			var container = $(this).parent().parent().parent().parent().parent();
			$(".catCenterWrapper").append($(this));
			
			//hr
			/*if (m == 2 || m == 5) {
				$("<hr class='thirtyeight catHr'>").insertAfter($(this));
			}*/
			
			m = m + 1;
		});
	//}
	$(".catTitleWrapper").css("marginTop", "23px");
	
	//Give margins to center wrapper
	$(".catCenterWrapper").css({"margin":"10px 0 10px 10px"});
	$("#frame-6_s").css("marginTop", "0px");
	//Left product margins
	$(".thirtyfive:first").css("marginLeft", "10px");
	$(".thirtyfive").eq(3).css("marginLeft", "10px");
	$(".thirtyfive").eq(6).css("marginLeft", "10px");
	$(".thirtyfive").eq(9).css("marginLeft", "10px");
	
	//Remove last hr
	if ($(".thirtyeight").length == 4)
		$(".thirtyeight:last").remove();
	
	//Pagination
	$("[src*='page_next.gif']").parent().html("Next >>");
	$("[src*='page_prev.gif']").parent().html("<< Prev");
	if ($("a:contains('Next >>')").length > 0 || $("a:contains('<< Prev')").length > 0) {
		if ($("a:contains('<< Prev')").length <= 0) {
			$("a:contains('Next >>'):first").parent().children().wrapAll("<div class='thirtynine categoryPagination'></div>");
			$("a:contains('Next >>'):last").parent().children().wrapAll("<div class='forty categoryPaginationBottom'></div>");
		}
		if ($("a:contains('Next >>')").length <= 0) {
			$("a:contains('<< Prev'):first").parent().children().wrapAll("<div class='thirtynine categoryPagination'></div>");
			$("a:contains('<< Prev'):last").parent().children().wrapAll("<div class='forty categoryPaginationBottom'></div>");
		}
		if ($("a:contains('Next >>')").length > 0 && $("a:contains('<< Prev')").length > 0) {
			$("a:contains('Next >>'):first").parent().children().wrapAll("<div class='thirtynine categoryPagination'></div>");
			$("a:contains('Next >>'):last").parent().children().wrapAll("<div class='forty categoryPaginationBottom'></div>");
		}
		$("<span style='color:#9b9b9b; margin-left:12px;'>Page:</span>").insertBefore($(".categoryPagination").children(":contains('1')"));
		$("<span style='color:#9b9b9b; margin-left:12px;'>Page:</span>").insertBefore($(".categoryPaginationBottom").children(":contains('1')"));
		//Move pagination wrappers
		$(".catCenterWrapper").prepend($(".categoryPagination"));
		$(".catCenterWrapper").append($(".categoryPaginationBottom"));
	}
	
	//Left Nav
	
	$(".leftnav-head").parent().children().wrapAll("<div class='fortythree catLeftNav'></div>");
	$(".leftnav-head").hide();
	$("#content-1").append($(".catLeftNav"));
	
	if ($("#leftnav-children").length <= 0) {
		$(".leftnav-head").removeClass("leftnav-head").addClass("leftnav-new-head").show();
		$(".leftnav-head").children().children().children("td#left, td#right").hide();
		$(".leftnav-sibling").css({"fontWeight":"normal", "lineHeight":"15px"}).show();
		$(".leftnav").css({"marginLeft":"10px"});
		$(".leftnav-sibling a, .leftnav a").css("fontWeight", "normal");
		$(".leftnav-sibling").css("marginLeft", "10px");
		/* Safari Fixes */
		if ($.browser.safari) {
		  $(".catLeftNav").children("table:first").css("marginLeft", "-32px");
		}
	}
	else
		$(".leftnav-sibling").remove();
	
	//remove table styling
	$("#button").css({"background":"none", "backgroundImage":"none"});
	$("#white, #grey").parent().remove();
	$("#grey").remove();
	$("[src*='dots_leftnav_foot.gif']").parent().parent().parent().parent().remove();
	$(".leftnav, .leftnav-child").removeAttr("width");
	
	//Hide parts
	
	$("#leftnav-6").remove();
	$(".leftnav-bg").show();
	$(".wba_contentright").children("table:first").hide();
	
	//Hide original table
	$(".searchLeftWrapper").prev("table").hide();
	$("#wba_main").hide();
	
	//Check for empty price again
	$(".product-price").each(function() {
		if ($(this).html() == '')
			$(this).remove();
	});
	
	$(".thirty").css("width", "616px");
	
	//Right Wrapper
	$("<div class='rightWrapper' style='float:left;'></div>").insertAfter($(".catCenterWrapper"));
	
	//Header images
	$(".catCenterWrapper").prepend($("#frame-1"));
	$("#frame-1").attr("id", "catHeader");
	
	$(".showsLeftWrapper").css("marginBottom", "17px");
	
	//Create main wrapper due to recently viewed and longer left navs
	$(".showsLeftWrapper").wrap("<div class='catMainWrapper'></div>");
	$(".catMainWrapper").append($(".catCenterWrapper"));
	$(".catMainWrapper").append($(".rightWrapper"));
}

function search () {
	//Hide widgets
	$("#frame-2_s").css("display", "none");
	$("#frame-3_s").css("display", "none");
	$("#frame-6_s").css("display", "none");
	
	//Content areas
	$(".content").append("<div class='twentynine searchLeftWrapper'></div>");
	$(".content").append("<div class='thirty searchCenterWrapper'></div>");
	
	//Header
	var keyword = $("h1").text().split(": ");
	var search = '"' + keyword[1] + '"';
	$(".content").prepend($("<div class='fortytwo searchHeader'>Search Results for " + search + "</div>"));
	$("h1").remove();
	
	//Give margins to wrappers
	$(".searchCenterWrapper, .searchLeftWrapper").css({"margin":"10px 0 0 10px"});
	
	//Apply product styling
	$("a.r").children("img").parent().wrap("<div class='thirtyfour catImageWrapper'></div>");
	$(".thirtyfour").wrap("<div class='thirtyfive catProductWrapper'></div>");
	$(".product-title").css("fontWeight", "bold");
	
	m = 0;
	$(".thirtyfive").each(function(i) {
		if (m == 4) 
			m = 0;
		//wrap title, price, add to cart
		$(this).next().next("a").wrap("<div class='thirtysix catTitleWrapper'></div>");
		var title = $(this).next().next("div");
		$(this).append($(title));
		
		if ($(this).parent().children("span.attribution").length > 0) {
			$(this).next().next().next().next().next().wrap("<div class='thirtyseven catPriceWrapper'></div>");
			var price = $(this).next().next().next().next().next("div");
		}
		else {
			$(this).next().next().next().wrap("<div class='thirtyseven catPriceWrapper'></div>");
			var price = $(this).next().next().next("div");
			
		}
		
		$(this).append($(price));
		var price = $(this).children(".catPriceWrapper");
		
		//create Add to cart
		$(this).children(".catTitleWrapper").children("a").clone().appendTo($(price)).html("Add to Cart");
		
		//move product divs out of table
		var container = $(this).parent().parent().parent().parent().parent();
		$(".searchCenterWrapper").append($(this));
		
		//hr
		if (m == 3 || m == 7) {
			$("<hr class='thirtyeight catHr'>").insertAfter($(this));
		}
		
		m = m + 1;
	});
	
	$(".thirtyfive").css({"width":"160px", "marginRight":"31px"});
	$(".thirtyeight").css({"width":"768px", "marginTop":"10px"});
	
	//take bold off add to cart
	$(".thirtyseven a").css("fontWeight", "normal");
	
	//Remove last hr
	$(".thirtyeight:last").remove();
	
	//Sort and Pagination
	//Pagination
	$("[src*='page_next.gif']").parent().html("Next >>");
	$("[src*='page_prev.gif']").parent().html("<< Prev");
	if ($("a:contains('Next >>')").length > 0 || $("a:contains('<< Prev')").length > 0) {
		if ($("a:contains('<< Prev')").length <= 0) {
			$("a:contains('Next >>'):first").parent().children().wrapAll("<div class='thirtynine searchPagination'></div>");
			$("a:contains('Next >>'):last").parent().children().wrapAll("<div class='forty searchPaginationBottom'></div>");
		}
		if ($("a:contains('Next >>')").length <= 0) {
			$("a:contains('<< Prev'):first").parent().children().wrapAll("<div class='thirtynine searchPagination'></div>");
			$("a:contains('<< Prev'):last").parent().children().wrapAll("<div class='forty searchPaginationBottom'></div>");
		}
		if ($("a:contains('Next >>')").length > 0 && $("a:contains('<< Prev')").length > 0) {
			$("a:contains('Next >>'):first").parent().children().wrapAll("<div class='thirtynine searchPagination'></div>");
			$("a:contains('Next >>'):last").parent().children().wrapAll("<div class='forty searchPaginationBottom'></div>");
		}
		$("<span style='color:#9b9b9b; margin-left:12px;'>Page:</span>").insertBefore($(".searchPagination").children(":contains('1')"));
		$("<span style='color:#9b9b9b; margin-left:12px;'>Page:</span>").insertBefore($(".searchPaginationBottom").children(":contains('1')"));
		//Move pagination wrappers
		$(".searchCenterWrapper").prepend($(".searchPagination"));
		$(".searchCenterWrapper").append($(".searchPaginationBottom"));
	}
	else {
		$(".searchCenterWrapper").prepend("<div class='thirtynine searchPagination'></div>");
	}
	
	//Sort By
	$(".searchCenterWrapper").prepend($("#sortBy"));
	
	//Left product margins
	$(".thirtyfive:first").css("marginLeft", "10px");
	$(".thirtyfive").eq(4).css("marginLeft", "10px");
	$(".thirtyfive").eq(8).css("marginLeft", "10px");
	$(".thirtyfive").eq(12).css("marginLeft", "10px");
	
	//Left Nav
	$(".leftnav-head").parent().children().wrapAll("<div class='fortythree searchLeftNav'></div>");
	$(".leftnav-head").hide();
	$(".searchLeftWrapper").append($(".searchLeftNav"));
	$(".searchLeftNav").prepend("<div style='margin:10px 0 5px 0;'>Narrow your search by:</div>");
	$(".leftnav-child").css("marginLeft", "0px");
	$(".leftnav, .leftnav-sibling").css("marginTop", "15px");
	$(".twentynine").css("height", "auto");
	$("<br>").insertBefore($(".leftnav-sibling #button a.searchBinItem"));
	$("#leftnav-children ul.filterWidget").css({"padding":"0px", "marginLeft":"-1px"});
	$("#leftnav-children ul.filterWidget .seeMore a").css({"fontSize":"12px", "fontWeight":"normal"});
	$(".leftnav #button a").css("color", "#333333");
	
	//remove table styling
	$("#button").css({"background":"none", "backgroundImage":"none"});
	$("#white, #grey").parent().remove();
	$("#grey").remove();
	$("[src*='dots_leftnav_foot.gif']").parent().parent().parent().parent().remove();
	$(".leftnav, .leftnav-child").removeAttr("width");
	
	//Hide parts
	$("#leftnav-sibling").remove();
	$("#leftnav-6").remove();
	$(".leftnav-bg").show();
	$(".attribution").hide();
	
	//Hide original table
	$(".searchLeftWrapper").prev("table").hide();
	
	//No Results
	if ($("#emptysearch-widget").length) {
		$(".noResultsTitle").css({
			"paddingLeft": "0px", 
			"textAlign":"center"
		});
		$(".searchCenterWrapper").append("<div class='fortyfour searchContinueShopping'><a href='/'>Continue Shopping</a></div>");
		$(".searchCenterWrapper").append($(".noResultsTitle"));
		$(".searchCenterWrapper").css({"width":"956px", "height":"400px"});
		$(".searchLeftWrapper").hide();
	}
}

function cart () {
	//Hide widgets
	$("#frame-2_s").css("display", "none");
	$("#frame-3_s").css("display", "none");
	
	//Styling
	$("#frame-2").attr("id", "content-2");
	$("#cart2").parent().addClass("sixtyone cartWrapper");
	$("#content-6").insertAfter($("#cart2")).removeAttr("id").addClass("eightyone").hide();
	$(".content").prepend($(".cartWrapper"));
	$(".content").children("table").remove();
	$("#content-2").css({"float":"left", "height":"526px", "marginBottom":"10px"});
	$("#frame-6_s").css("clear", "both");
	$("#frame-6_s").css("marginTop", "10px");
	$(".cartWrapper").wrap("<div class='cartMainWrapper'></div>");
	$(".cartMainWrapper").append($("#content-2"));
	$("#frame-6_s").insertAfter($(".cartMainWrapper"));
	
	//Empty Cart
	if ($("#cart2").length <= 0) {
		$(".content").prepend("<div class='noResultsTitle'>Your cart is empty.</div>");
		$(".content").prepend("<div class='fortyfour searchContinueShopping'><a href='/'>Continue Shopping</a></div>");
		$("#content-2").hide();
		$(".content").css("paddingTop", "25px");
		$(".noResultsTitle").css({
			"paddingLeft": "0px", 
			"textAlign":"center",
			"height":"200px"
		});
	}
	
	//Table Styling
	//Top Buttons
	$("#cart2").children().children("tr:first").css({"height":"45px"}).children("td").attr("valign", "top").children("a:first");
	$("#cart2").children().children("tr:first").children().children(":first").clone().insertBefore($("[src*='vh1_checkoutbtn.jpg']:last").parent());
	
	//remove last column
	$("#cart2").children().children().children(":nth-child(5)").remove();
	$(".itemTotalPrice").remove();
	
	//Lines between products
	$(".line").removeClass("line").html("<hr class='thirtyeight cartHr'>");
	
	//Product Rows
	$(".itemImage").children().wrap("<div class='thirtyone sixtytwo'></div>");
	//Description
	$(".itemDescription").css("paddingRight", "15px");
	$(".itemShipping").css({"font-weight":"normal", "fontSize":"13px"});
	$(".itemSKU").hide();
	//Quantity/Update
	$(".itemQuantity").children("input.cart").next().css({"width":"14px", "height":"14px", "border":"1px solid #999999", "fontSize":"11px", "padding":"3px"})
	$(".itemRemove").children().attr("src", "http://vh1.amazonwebstore.com/images/vh1_cart_remove_btn.gif");
	$(".updateItem").attr("src", "http://vh1.amazonwebstore.com/images/vh1_cart_update_btn.gif");
	
	/* IE7 Fixes */
	if ($.browser.msie) {
		if ($.browser.version == '7.0') {
			$("#cart2").attr("cellSpacing", "0");
		}
	}

	$(".line-fade, .cartHr").parent().attr("colspan", "4");
	$("#cartTotalLabel").parent().parent().parent().parent().attr("colspan", "4").css({"padding":"15px 0 15px 0", "textAlign":"left"});
	$("#cartTotalLabel").css("width", "143px").parent().parent().parent().attr("align", "left");
	$("#cartTotalLabel").parent().parent().parent().css("marginLeft", "398px");
	
	//Last Row 
	$(".itemInfo:last td").css("borderBottom", "5px solid #e6e6e6").parent().next().next().children().css("padding", "15px 0");
	
	
	//Change breadcrumb to be header
	var header = $(".breadcrumbWrapper span.crumbPast:last");
	$(".breadcrumbWrapper").html(header);
	
	//Header
	$("<div class='thirtythree breadcrumbWrapper' style='margin-left:10px;'>Cart</div>").insertBefore($(".cartWrapper"));
	
	//Continue Shopping
	//("<div class='fortyfour searchContinueShopping'><a href='/'>Continue Shopping</a></div>");
	$("[src*='btn_continue_shopping2.gif']").parent().html("Continue Shopping");
	$("#continueShopping").parent().html("Continue Shopping");
	$("a:contains('Continue Shopping')").addClass("seventytwo continueShoppingBtn");
	$(".continueShoppingBtn").parent().css("verticalAlign", "middle").attr("colspan", "4");

	$("#safeandsecure").prev().prev("a").css("marginRight", "0px");
	
	$("#cartTotal, #estimatedShippingTotal").css({"paddingLeft":"10px", "fontWeight":"normal", "textAlign":"left"});
	$("#cartTotal").css("fontSize", "13px");
	
	
	$("#frame-6_s").css("marginTop", "0px");
	
	//checkout rollover effect
	$("[src*='vh1_checkoutbtn.jpg']").addClass("checkoutButton");
	$(".checkoutButton").hover(
		function () {
    		$(this).attr("src", "http://vh1.amazonwebstore.com/images/vh1_checkoutbtn_on.jpg");
  		},
  		function () {
    		$(this).attr("src", "http://vh1.amazonwebstore.com/images/vh1_checkoutbtn.jpg");
  		}
	);
	
}

function myAccount () {
	//Hide widgets
	$("#frame-2_s").css("display", "none");
	$("#frame-3_s").css("display", "none");
	
	//Main Content
	$(".content").children("table:first").addClass("sixtyfive orderConfirmationWrapper");
	$("#wba_main").css("margin", "10px");
	$(".orderConfirmationWrapper").css("fontSize", "13px");
	
	//Styling
	$("h3").css({"fontWeight":"bold", "margin":"15px 0 5px 0"});
	$("#wba_main [src*='vh1_go_btn.jpg']").attr("width", "").attr("height", "").css("margin", "0 0 0 5px").parent().css({"verticalAlign":"bottom", "paddingBottom":"2px"});
	$("input:[name*='orderID']").addClass("orderIdGo");
	
	//$("a:contains('Privacy Policy')").attr("href", "http://www.vh1.com/sitewide/legal/privacy.jhtml");
	$("a:contains('Shipping Policy'), a:contains('Return Policy'), a:contains('Privacy Policy')").attr("href", "/content/Help.htm");
}

function orderConfirmation () {
	//Hide widgets
	$("#frame-2_s").css("display", "none");
	$("#frame-3_s").css("display", "none");
	$("#frame-2").remove();
	
	//Main Content
	$(".content").children("table:first").addClass("sixtyfive orderConfirmationWrapper");
	$(".orderConfirmationWrapper").css("fontSize", "13px");
	$("#wba_main").css({"margin":"10px", "width":"936px"});
	
	//Styling
	
	//Top Section
	var email = $(".orderConfirmationWrapper div:first").html();
	var emailsplit = email.split("An ");
	var emailfinal = $(".orderConfirmationWrapper div:first").text().split("An ");
	
	$("<div class='seventyfour orderConfirmThanks'></div>").insertBefore($(".orderConfirmationWrapper div:first"));
	$(".orderConfirmThanks").append("<div class='seventyfive orderthanks'>Thank you for placing your order.</div>");
	$(".orderConfirmThanks").append("<div class='seventysix orderEmail'>An " + emailfinal[1] + "</div>");
	$(".orderConfirmThanks").next("div").hide();
	
	$("b:contains('Order Number: ')").parent().addClass("seventyseven orderInfo");
	$(".orderInfo").parent().parent().parent().prev("br").remove();
	$(".orderInfo").next().hide();
	$(".orderInfo").children("br").remove();
	
	//Items
	$("b:contains('Item'):first").parent().parent().attr("id", "itemHeaders");
	$("#itemHeaders").parent().parent().addClass("itemTable").children().children().children("td").css("verticalAlign", "top");
	
	//If another table is present
	$(".itemTable").next().next("table").addClass("itemTable");
	$(".itemTable").children().children("tr:first").next().attr("id", "itemHeaders");
	$(".itemTable").children().children().children("td").css("verticalAlign", "top");
	
	$("#itemHeaders").children("td:first").css("width", "100px");
	$(".itemTable").children().children().children().children("img").wrap("<div class='thirtyone sixtytwo'></div>");
	$(".itemTable strong").parent().parent().addClass("confirmDescription itemInfo");
	$(".confirmDescription").children().children("strong").parent().addClass("itemDescription").css("paddingRight", "15px");
	$(".itemDescription").html($(".itemDescription").children("strong").text());
	
	//Fix headers
	$("#itemHeaders").children("td:first").html("<b>Item</b>").next().html("<b>Name</b>");
	
	//Move Status
	$($("#wba_main strong:first")).addClass("eighty orderConfirmStatus").insertBefore($(".itemTable"));
	$(".orderConfirmStatus").prev("table").css("marginBottom", "10px");
	
	//remove last column
	$("b:contains('Shipping / Handling:'), b:contains('Sub Total:'), b:contains('Estimated Tax:'), b:contains('Total:')").parent().attr("colspan", "3").parent().children("td:last").css({
		"textAlign": "left",
		"fontWeight":"normal",
		"fontSize":"13px"
	}).prev().css("paddingRight", "7px");
	$("b:contains('Shipping / Handling:')").parent().css({"paddingRight":"7px", "fontSize":"11px", "height":"20px"}).next().attr("align", "left").css("fontSize", "11px");
	$("b:contains('Sub Total:')").parent().css({
		"paddingRight": "7px",
		"height":"40px",
		"paddingTop":"20px"
	}).next().attr("align", "left").css({"paddingTop":"20px"});
	$("b:contains('Estimated Tax:')").parent().css({
		"paddingRight": "7px",
		"height":"20px"
	}).next().attr("align", "left");
	$("#totalLabel").css("paddingRight", "7px");
	$("#totalValue").css("fontWeight", "normal").attr("align", "left");
	$(".itemTable").children().children().children(":nth-child(5)").css("display", "none");
	$(".itemTable").children().children().children(":nth-child(4)").css("textAlign", "left");
	
	//remove image hover state 
	$(".sixtytwo").css("border", "none");
	$(".sixtytwo").hover(
		function () {
    		$(this).css("border", "none");
  		},
  		function () {
    		$(this).css("border", "none");
  		}
	);
}

function orderStatus () {
	//Hide widgets
	$("#frame-2_s").css("display", "none");
	$("#frame-3_s").css("display", "none");
	$("#frame-2").remove();
	
	//Main Content
	$(".content").children("table:first").addClass("sixtyfive orderConfirmationWrapper");
	$(".orderConfirmationWrapper").css("fontSize", "13px");
	$("#wba_main").css({"margin":"10px", "width":"936px"});
	
	//Styling
	$("b:contains('Item'):first").parent().parent().attr("id", "itemHeaders");
	$("#itemHeaders").parent().parent().addClass("itemTable").children().children().children("td").css("verticalAlign", "top");
	$("#itemHeaders").children("td:first").css("width", "100px");
	$(".itemTable").children().children().children().children("img").wrap("<div class='thirtyone sixtytwo'></div>");
	$(".itemTable span.tiny").parent().parent().addClass("confirmDescription itemInfo");
	$(".confirmDescription").children().children("span.tiny").parent().addClass("itemDescription").css("paddingRight", "15px");
	$("span.tiny").hide();
	$("input:[name*='orderID']").addClass("orderIdGo").css("marginBottom", "20px");
	
	
	//Fix headers
	$("#itemHeaders").children("td:first").html("<b>Item</b>").next().html("<b>Name</b>");
	$(".itemTable").css("marginTop", "30px");
	$("h3").css("fontWeight", "bold");
	
	//Last Row 
	$(".itemInfo:last td").css("borderBottom", "5px solid #e6e6e6").parent().next().next().children().css("padding", "15px 0");
	
	//remove last column
	$("b:contains('Shipping / Handling:'), b:contains('Sub Total:'), b:contains('Tax:'), b:contains('Total:')").parent().attr("colspan", "3").parent().children("td:last").css({
		"textAlign": "left",
		"fontWeight":"normal",
		"fontSize":"13px"
	}).prev().css("paddingRight", "7px");
	$("b:contains('Shipping / Handling:')").parent().css({"paddingRight":"7px", "fontSize":"11px", "height":"20px"}).next().attr("align", "left").css("fontSize", "11px");
	$("b:contains('Sub Total:')").parent().css({
		"paddingRight": "7px",
		"fontSize": "11px",
		"height":"40px",
		"paddingTop":"20px"
	}).next().attr("align", "left").css({"fontSize":"11px", "paddingTop":"20px"});
	$("b:contains('Tax:')").parent().css({
		"paddingRight": "7px",
		"fontSize": "11px",
		"height":"20px"
	}).next().attr("align", "left").css("fontSize", "11px");
	$("#totalLabel").css("paddingRight", "7px");
	$("#totalValue").css("fontWeight", "normal").attr("align", "left");
	$(".itemTable").children().children().children(":nth-child(5)").css("display", "none");
	$(".itemTable").children().children().children(":nth-child(4)").css("textAlign", "left");
	$("b:contains('Total:')").css("fontSize", "11px");
	
	$("#wba_main input").attr({"width":"", "height":""}).css("marginRight", "5px").parent().css("verticalAlign", "top");
	$("#wba_main input:first").attr("height", "26px");
	$("#wba_main [src*='vh1_go_btn.jpg']").attr({"width":"", "height":"20px"}).css("margin", "0 0 0 5px").parent().css({"verticalAlign":"bottom", "paddingBottom":"2px"});
	
	//Bottom Section
	$("b:contains('Carrier Name')").parent().parent().parent().parent().addClass("seventynine orderStatusBottom");
}

function help () {
	//Hide widgets
	$("#frame-2_s").css("display", "none");
	$("#frame-3_s").css("display", "none");
	$("#frame-6_s").css("display", "none");
	
	$(".content").prepend($(".helpPage"));
	
	$("p").css("marginTop", "15px");
	$("h2").css({"fontSize":"16px", "fontWeight":"bold"});
	$("h3").css({"fontSize":"14px", "fontWeight":"bold"});
	$(".helpPage ul").css({"marginTop":"15px", "marginLeft":"20px"});
	$(".helpPage ol").css({"marginTop":"15px", "marginLeft":"20px"});
	$(".helpPage ul li").css({"listStyle":"disc"});
	$(".helpPage ol li").css({"listStyle":"decimal"});
	$("h3").css("marginTop", "15px");
}

function details () {
	//Hide widgets
	$("#frame-3_s").css("display", "none");
	
	//Move Widgets
	$("#frame-7").attr("id", "content-10");
	$("#content-10").insertAfter($("#frame-2_s"));
	$("#frame-8").attr("id", "content-11");
	$("#content-11").insertAfter($("#content-10"));
	$("#leftnav-6").attr("id", "content-2");
	$("#content-10").css("marginTop", "10px");
	
	//Center Wrapper
	$(".wba_contentright").children("table:first").wrap("<div class='fiftynine detailsCenterWrapper'></div>");
	$(".wba_contentright").next().remove();
	$(".content").prepend($(".detailsCenterWrapper"));
	
	//Left Wrapper
	$("#content-2").wrap("<div class='twentynine showsLeftWrapper'></div>");
	$(".content").prepend($(".showsLeftWrapper"));
	if (window.location.href.indexOf("B00579MU1G") < 0)
		$(".showsLeftWrapper").css("height", "1075px");
	
	//Left Nav
	
	$(".leftnav-bg").show();
	$(".leftnav-head").parent().children().wrapAll("<div class='fortythree detailsLeftNav'></div>");
	$(".leftnav-sibling").css({"margin":"0px 10px 0", "lineHeight":"15px"}).hide();
	$(".leftnav-head").hide();
	$(".showsLeftWrapper").prepend($(".detailsLeftNav"));
	$(".detailsLeftNav table").attr("width", "");
	$("[src*='dots_leftnav_foot.gif']").parent().hide();
	
	if ($("#leftnav-children").length <= 0) {
		$(".leftnav-head").removeClass("leftnav-head").addClass("leftnav-new-head").show();
		$(".leftnav-head").children().children().children("td#left, td#right").hide();
		$(".leftnav-sibling").css({"fontWeight":"normal", "lineHeight":"15px"}).show();
		$(".leftnav").css({"margin":"5px 0 0 10px"});
		$(".leftnav-sibling a, .leftnav a").css("fontWeight", "normal");
		$(".  leftnav-new-head #left, .leftnav-new-head #right").hide();
		
	}
	if ($(".detailsLeftNav td:contains('Shop')").length > 0) {
			$(".detailsLeftNav").hide();
		}
	
	//Product Information
	//Header
	$(".detailsCenterWrapper").prepend("<div class='sixty productHeader'></div>");
	$(".productHeader").html($("h1").html());
	//Image
	//resizeImages($("#productImage"), 160, 160);
	$("#productImage").parent().parent().parent().parent().parent().parent().parent().parent().attr("width", "").parent().attr("width", "");
	$("#productImage").parent().parent().parent().parent().parent().parent().parent().parent().parent().attr("width", "").css("width", "160px");
	$("#productImage").css({"maxWidth":"160px", "maxHeight":"160px"});
	$("#productImage").parent().parent().css({"verticalAlign":"top", "width":"160px"});
	//Details
	$("<div class='sixtysix productDetailsWrapper'></div>").insertAfter($(".productHeader"));
	
	//Product Image Column
	//Zoom
	$("#productImage").parent().parent().parent().parent().parent().parent().parent().next().children().children().children().children().children().children().addClass("sixtyseven zoomImage");
	
	$("#productImage").parent().wrap("<div class='seventyone detailsImageWrapper'></div>");
	$(".detailsImageWrapper").wrap("<div class='sixtyeight detailsImageColumnWrapper'></div>");
	$(".detailsImageColumnWrapper").append($("<div class='sixtynine zoomWrapper'></div>"));
	$(".zoomWrapper").append($(".zoomImage"));	
	
	$(".productDetailsWrapper").append($(".detailsImageColumnWrapper"));
	
	//Right Column
	$(".productDetailsWrapper").append("<div class='sixtyfour productDetailsRight'></div>");
	$(".wbaProductRatingWidget").parent().css("paddingBottom", "15px");
	if ($(".our-label").length > 0)
		$(".our-label").parent().parent().parent().parent().parent().parent().parent().addClass("seventy detailsTableWrapper");
	else 
		$("#sku").parent().parent().parent().addClass("seventy detailsTableWrapper");
	$(".productDetailsRight").append($(".detailsTableWrapper"));
	$("#inStock").css({"fontSize":"11px"});
	$(".detailsTableWrapper .wba_add_to_cart_btn").removeClass("wba_add_to_cart_btn");
	$(".detailsTableWrapper .preorder_btn").removeClass("preorder_btn").attr("src", "/images/mtv_addtocartbtn.jpg");
	$("#shippingMainLabel").hide();
	$(".shipping").parent().parent().hide();
	$(".detailsTableWrapper span.thirdPartyWarning").hide();
	
	//Instock
	if ($("#inStock").parent().parent().prev().children().html() == '&nbsp;')
		$("#inStock").parent().parent().prev().remove();
	$("#inStock").parent().css("padding", "15px 0 0 0");
	
	$(".detailsTableWrapper td").each(function() {
		if ($(this).html() == '&nbsp;')
			$(this).parent().remove();
	});
	//Out of stock
	$("span.sale:contains('Out of stock')").hide();
	$("span#parentAvailability:contains('Out of stock')").css("fontWeight", "bold");
	$(".detailsImageColumnWrapper").css("height", "190px")
	
	
	//Shipping
	var shipping = $("td:contains('Shipping: ')");
	$(shipping).next().prepend($("<span class='shipping'>Shipping: </span>")).attr("colSpan", "2").prev().remove();
	$(".shipping").css("fontWeight", "bold").parent().css("paddingTop", "14px").children("b").css("fontWeight", "normal");
	
	//Availability
	$("#parentAvailability").parent().parent().css("padding", "5px 0 10px 0");
	var avail = $("#parentAvailability").text();
	var availability = avail.substring(0,4);
	if (availability != 'This')
		$("b:contains('Availability:')").remove();
	$("#limitedQuantity").parent().css("paddingBottom", "10px");
	
	//Share
	$("<div class='seventyeight detailsShare'>Share on</div>").insertAfter($(".detailsTableWrapper"));
	$(".detailsShare").append($("<a href='http://www.facebook.com/sharer.php?u=http://vh1.amazonwebstore.com" + wba_product.productDetailUrl + "' style='margin: 2px 0 0 3px;; color: rgb(0, 119, 187);' target='_blank'><img src='http://vh1.amazonwebstore.com/images/mtv_shop_boutique_fb.png'></a>"));
	$(".detailsShare").append($("<a href='http://twitter.com/home?status=http://vh1.amazonwebstore.com" + wba_product.productDetailUrl + "' style='margin: 2px 0 0 5px; color: rgb(0, 119, 187);' target='_blank'><img src='http://vh1.amazonwebstore.com/images/mtv_shop_boutique_twitter.png'></a>"));
	
	//Hide Zoom, Email, Sku
	$("a:contains('Email')").hide().siblings().hide();
	$("a:contains('Zoom')").hide().siblings().hide();
	$("#sku").parent().remove();
	
	//Description
	$("strong:not(:contains('CHOKING HAZARD'))").parent().parent().parent().parent().addClass("sixtythree productDescriptionWrapper");
	$(".productDescriptionWrapper strong:not(:contains('CHOKING HAZARD'))").css({"fontSize":"19px", "fontWeight":"bold"}).parent().css({"borderTop":"1px dotted #d9d9d9",  "padding":"15px 0 8px 0"});
	$(".productDescriptionWrapper h2").css("fontSize", "13px");
	$(".productDescriptionWrapper .line-fade").parent().parent().remove();
	$("#description p").css({"fontFamily":"Arial", "fontSize":"13px"});
	$("#features li").css({"list-style":"disc", "marginLeft":"15px"});
	
	//Color
	$("strong:contains('Color')").parent().parent().next().children().children().children().children().children().children("span").wrap("<div style='float:left; margin-bottom:10px;'></div>");
	
	//Change td size in Details
	$(".productDetails").children().children("td:first").css("width", "175px");
	$(".productDescriptionWrapper").insertAfter($(".productDetailsWrapper"));
	
	//add to cart rollover effect
	$("[src*='vh1_addtocartbtn.jpg']").addClass("addtocartButton");
	$(".addtocartButton").hover(
		function () {
    		$(this).attr("src", "http://vh1.amazonwebstore.com/images/vh1_addtocartbtn_on.jpg");
  		},
  		function () {
    		$(this).attr("src", "http://vh1.amazonwebstore.com/images/vh1_addtocartbtn.jpg");
  		}
	);
	
	//Remove old table
	$(".productDescriptionWrapper").next("table").hide();
	
	//Right Wrapper
	$("<div class='rightWrapper' style='float:left;'></div>").insertAfter($(".detailsCenterWrapper"));
	
	$(".rightWrapper").next("table").css("clear", "both");
	
	if ($(".zoomWrapper").children("img").length > 3)
		$(".detailsImageColumnWrapper").css("height","230px");
}

function specialCat (page) {
	if (page == 'vh1classic')
		$("<div class='specialCatHeader'><img src='http://vh1.amazonwebstore.com/images/Vh1ClassicHeader_786x235.jpg' alt='VH1 Classic'></div></a>").insertBefore($(".showsLeftWrapper"));
	$(".thirtynine, .thirtyfive, .categoryPaginationBottom").hide();
	
	$(".showsLeftWrapper").css("marginTop", "245px");
	$(".catCenterWrapper").css("marginTop", "255px");
	$(".catShowHeader").css({
		"margin": "0px",
		"position":"absolute"
	});
	//$(".catShowHeader").html("<div style='font-size: 27px; padding: 0px;' class='product-widget-label'><h2><span>Featured Products</span></h2></div>");
	//$("#frame-2").children("div").html("<img src='/images/mtv_Jackass10thAnniversary_160x600.jpg' alt='Jackass'>");
	
	$(".catCenterWrapper").append($("#specialCat-1"));
	$(".catCenterWrapper").append($("#specialCat-2"));
	$(".catCenterWrapper").append($("#specialCat-3"));
	$(".catCenterWrapper").append($("#specialCat-4"));
	$("<hr class='thirtyeight catHr'>").insertAfter($("#specialCat-1"));
	$("<hr class='thirtyeight catHr'>").insertAfter($("#specialCat-2"));
	$("<hr class='thirtyeight catHr'>").insertAfter($("#specialCat-3"));
	$(".catCenterWrapper .twenty").addClass("thirtyfive").removeClass("twenty");
	$(".catCenterWrapper .nineteen").addClass("fortyone");
	$(".catCenterWrapper .eighteen").removeClass("eighteen");
	$(".catCenterWrapper .nineteen").addClass("thirtyfour").removeClass("nineteen");
}


/* Resize Images */
// element = element enclosing images
function resizeImages (element, width, height) {
	$(element).each(function() {
		if ($(this).attr("src") == '/shared/images/no_image_s.gif' || $(this).attr("src") == '/shared/images/no_image_m.gif' || $(this).attr("src") == '/shared/images/no_image_l.gif') {
			$(this).attr("width", width);
			$(this).attr("height", height);
		}
		else {
			var w = parseInt($(this).css("width"));
			var h = parseInt($(this).css("height"));
			var changed = false;
			
			if (w > width) {
				var f = 1 - ((w - width) / w);
				w = w * f;
				h = h * f;
				changed = true;
			}
			
			if (h > height) {
				var f = 1 - ((h - height) / h);
				w = w * f;
				h = h * f;
				changed = true;
			}
			
			if (h < height) {
				var diff = height - h;
				var top = diff/2;
				$(this).css("marginTop", top);
			}
			
			if (changed = true) {
				$(this).css("width", w);
				$(this).css("height", h);
			}
		}
	});
}

/* Truncate Text */
function truncateText (element, length) {
	$(element).each(function() {
		var str = $(this).text();
		var limit = length;
		var bits, i;
		
		bits = str.split('');
		if (bits.length > limit) {
			for (i = bits.length - 1; i > -1; --i) {
			if (i > limit) {
			bits.length = i;
			}
			else if (' ' === bits[i]) {
			bits.length = i;
			break;
			}
			}
			bits.push('...');
		}
		var truncate = bits.join('');
		$(this).text(truncate);
	});
}

//Category images
function insertImage (img, category) {
$(".catShowHeader").html("<img src='http://vh1.amazonwebstore.com/images/" + img + "' alt='" + category + "'>");
}






