// Director > Main (document ready)

$(document).ready(function(){
	// Hide everything while loading and rendering
	$("body").hide();
	
	oldScripts();

	// Scan through all $("div")'s (can add more element types to selector) on the page
	$("div").each(function() {
		// Extract the text of each div and convert it to all lowercase
		var thisText = $(this).text().toLowerCase();
		// Depending on what the text of each div equals
		switch(thisText) {
			// For new products, featured products, dvds, and recently view items
			case "new products": case "featured products": case "dvds": case "recently viewed items": case "related items": case "customers who bought items in your shopping cart also bought": case "you may also like ...": case "items recently viewed":
				// Eliminate spaces from text (i.e. new products > newproducts)
				var thisText = thisText.split(' ').join('');
				// Add classes: areaNumber, semantic name, and actual text > gives us multiple ways to select this
				// Product Section Label div
				$(this).attr("class", "fifteen productSectionLabel " + thisText)
					// Product Section Label  (next) Product Listing div
					.next("div").attr("class", "sixteen productListingBin " + thisText)
					// Product Section Label div (next) Product Content div (children) Columns in this tables SECOND row
					.children("table").children("tbody").children("tr:nth-child(2)").children("td:nth-child(2)").children("table").children("tbody").children(":nth-child(2)").each(function() {
						// Assign class names $(".productImage") and $(".productTitle") for the second children <tr>
						$(this).attr("class", "seventeen productItemBin " + thisText)
							// These <td> elements alternate between the product's image(even) and title/link(odd)
							.children(":even").attr("class", "eightteen productImage " + thisText)
							.parent().children(":odd").attr("class", "nineteen productTitle " + thisText);
					})
					// Product Money Bin: contains the product pricing and order button as alernating <td>, Price(:first), Button(.next())
					.parent().children(":nth-child(4)").each(function() {
						// Assign class names $(".productMoneyBin") to the fourth child <tr>
						$(this).attr("class", "twenty productMoneyRow " + thisText)
							// These <td> elements alternate between the product's price(:first) and order button(:last or .next())
							.children().attr("class", "twentyone productMoneyBin " + thisText)
							.children("table").children("tbody").children("tr").children("td:nth-child(1)").attr("class", "twentytwo productPrice " + thisText)
							.next().attr("class", "twentythree productOrderButton " + thisText);
					});
					break;
			case "top sellers": 
				// Eliminate spaces from text (i.e. new products > newproducts)
				var thisText = thisText.split(' ').join('');
				// Add classes: areaNumber, semantic name, and actual text > gives us multiple ways to select this
				// Product Section Label div
				$(this).attr("class", "fifteen productSectionLabel " + thisText)
					// Product Section Label  (next) Product Listing div
					.next("div").attr("class", "sixteen productListingBin " + thisText)
					// Product Section Label div (next) Product Content div (children) Columns in this tables SECOND row
					.children("table").children("tbody").children("tr:nth-child(2)").children("td:nth-child(2)").children("table").children("tbody").children(":nth-child(5n+2)").each(function() {
						// Assign class names $(".productImage") and $(".productTitle") for the second children <tr>
						$(this).attr("class", "seventeen productItemBin " + thisText)
							// These <td> elements alternate between the product's image(even) and title/link(odd)
							.children(":even").attr("class", "eightteen productImage " + thisText)
							.parent().children(":odd").attr("class", "nineteen productTitle " + thisText);
					})
					// Product Money Bin: contains the product pricing and order button as alernating <td>, Price(:first), Button(.next())
					.parent().children(":nth-child(5n+4)").each(function() {
						// Assign class names $(".productMoneyBin") to the fourth child <tr>
						$(this).attr("class", "twenty productMoneyRow " + thisText)
							// These <td> elements alternate between the product's price(:first) and order button(:last or .next())
							.children().attr("class", "twentyone productMoneyBin " + thisText)
							.children("table").children("tbody").children("tr").children(":first").attr("class", "twentytwo productPrice " + thisText)
							.next().attr("class", "twentythree productOrderButton " + thisText);
					});
				case "you may also like":
					// Eliminate spaces from text (i.e. new products > newproducts)
					var thisText = thisText.split(' ').join('');
					// Add classes: areaNumber, semantic name, and actual text > gives us multiple ways to select this
					// Product Section Label div
					$(this).attr("class", "fifteen productSectionLabel " + thisText)
						// Product Section Label  (next) Product Listing div
						.next("div").attr("class", "sixteen productListingBin " + thisText)
						// Product Section Label div (next) Product Content div (children) Columns in this tables SECOND row
						.children("table").children("tbody").children("tr:nth-child(2)").children("td:nth-child(2)").children("table").children("tbody").children(":nth-child(5n+2)").each(function() {
							// Assign class names $(".productImage") and $(".productTitle") for the second children <tr>
							$(this).attr("class", "seventeen productItemBin " + thisText)
								// These <td> elements alternate between the product's image(even) and title/link(odd)
								.children(":even").attr("class", "eightteen productImage " + thisText)
								.parent().children(":odd").attr("class", "nineteen productTitle " + thisText);
						})
						// Product Money Bin: contains the product pricing and order button as alernating <td>, Price(:first), Button(.next())
						.parent().children(":nth-child(5n+4)").each(function() {
							// Assign class names $(".productMoneyBin") to the fourth child <tr>
							$(this).attr("class", "twenty productMoneyRow " + thisText)
								// These <td> elements alternate between the product's price(:first) and order button(:last or .next())
								.children().attr("class", "twentyone productMoneyBin " + thisText)
								.children("table").children("tbody").children("tr").children(":first").attr("class", "twentytwo productPrice " + thisText)
								.next().attr("class", "twentythree productOrderButton " + thisText);
						});
				break;
		}
	});
		
	// Append "Price: " label before the actual price
	$(".productPrice").each(function() {
		$(this).html("<h5>"+$(this).text()+"</h5>");
	});
	
	$(".productOrderButton").each(function() {
		$(this).children().wrapAll("<div class='twentyfour buttonWrapper'></div>");
	});
	
	$(".productImage").each(function() {
		$(this).children().wrapAll("<div class='twentyfive imageWrapper'></div>");
	});
	
	$(".productTitle").each(function() {
		var parentClasses = $(this).parent().attr("class").split(" ");
		$(this).children().wrapAll("<div class='twentysix titleWrapper " + parentClasses[2]+"Title'></div>");
	});
	
	$(".productItemBin").parent().parent().wrap("<div class='twentyseven listingsBinWrapper'></div>");
	
	$(".productPrice").parent().parent().parent().wrap("<div class='twentyeight productMoneyWrapper'></div>");
	
	$("#frame-3_s-3").wrap("<div class='thirty topSellersWrapper'></div>");
	$("#frame-6_s-3").wrap("<div class='thirty topSellersWrapper'></div>");
	
	//$(".wba_maintable").wrap("<div class='thirtytwo mainContentWrapper'></div>");
	
	$("#frame-3_s-2, #frame-6_s-2").css("padding", "0px");
	
	$(".listingsBinWrapper:last").addClass("twentynine");
	
	$("#frame-3_s-3 .listingsBinWrapper").addClass("thirtyone");
	$("#frame-6_s-3 .listingsBinWrapper").addClass("thirtyone");
	//$("#frame-6_s-3").wrap("<div class='thirty topSellersWrapper'></div>");
	
	$(".leftnav-bg").removeAttr("style");
	$(".topsellersTitle a, .newproductsTitle a, .featuredproductsTitle a, .dvdsTitle a, .recentlyvieweditemsTitle a, .relateditemsTitle a").css({
		"fontSize": "12px",
		"textDecoration":"none",
		"fontWeight": "bold"
	});
	
	$("table#leftnav-holder").hide();
		
	
	$("#leftcol-col-21").css("background", "none");
	$("[src*='btn_preorder.gif']").attr("src", "http://southparkstudios.amazonwebstore.com/images/spbtnaddtocart.png");
	
	//BreadCrumb
	
	$(".crumbPast").css("color", "black");
	$(".crumbPast:last h2").css("textDecoration", "underline");
	$(".crumbPast:last b").css("textDecoration", "underline");
	$(".crumbHome").parent().children().wrapAll("<div class='thirtythree breadCrumbWrapper'></div>");
	$(".crumbPast").children("h2").css("fontSize", "14px");
	$("[src*='orange_closed.gif']").remove();
	$("<span style='font-size:14px; font-weight:bold;'> > </span>").insertBefore($(".crumbPast").children("h2"));
	$("<span style='font-size:14px; font-weight:bold;'> > </span>").insertBefore($(".crumbPast").children("h3"));
	$("<span style='font-size:14px; font-weight:bold;'> > </span>").insertBefore($(".crumbPast").children("b").parent());
	$(".leftnav-bg").prepend($(".breadCrumbWrapper"));
	$("#breadcrumb").css("display", "none");
	$("span.crumbPast:last").css("textDecoration", "underline");
	$("span.crumbPast:last span").css("textDecoration", "none");
	$("span:contains(' &gt; ')").css("textDecoration", "none");
	//alert($(".thirtythree").html());
	//$("#leftcol").remove();
	
	$("[src*='no_image_s.gif']").css({
		"width": "76px",
		"height": "76px"
	});
	$("[src*='no_image_m.gif']").css({
		"width": "100px",
		"height": "100px"
	});
	$("[src*='no_image_l.gif']").css({
		"width": "100px",
		"height": "100px"
	});
	
	pageDirector();
	
	$("[src='/themes/sport/variations/blue/images/orange_closed.gif']").siblings("crumbHome").next().css("textDecoration", "none").text("next >>");
	
	// <a> click events fade body out
/*
	$("a:not('.fiftyone a')").live("click", function() {
		$("body").hide();
		$("body").live("mouseover", function() {
			$(this).show().die("click");
		});
	});
*/
	
	setTimeout(function() {
		$("body").show();
	}, 500);
	
});

function pageDirector() {
	// Run different scripts to format different pages
	var thisPage = location.href.substring((location.href.lastIndexOf("/"))+1),
		thisURL = window.location.href.split("/"),
		thisSubPage = thisURL[3].substring(0,6);
		thisQueryString = thisURL[3].substring(0,1);
		//alert(thisSubPage);
	// Scripts to pull out content from tables
	if (thisQueryString == '?') {
		topSellers("home");
		listings();
		if ($("#frame-4_s-col-2").length > 0) {
			$("#frame-4_s").css("display", "block");
		}
		else	
			$("#frame-4_s").css("display", "none");
	}
	else {
		switch(thisSubPage) {	
			case "catego":
				overlay("category");
				//if (thisURL[6] != 'Apparel.htm') 
				topSellers("details");
				listings();
				category();

				break;
			case "search":
				topSellers("details");
				listings();
				break;
			case "":
				overlay("home");
				topSellers("home");
				listings();
				if ($("#frame-4_s-col-2").length > 0) {
					$("#frame-4_s").css("display", "block");
				}
				else	
					$("#frame-4_s").css("display", "none");
				break;
			case "cart.h":
				$("#frame-4_s").remove();
				listings();
				topSellers("cart");
				$("#frame-5 .itemBin h5").prepend("Price: ");
				if ($("#frame-5 .productListingBin ").length > 0) {
					$("#frame-5").css("display", "block");
				}
				else	
					$("#frame-5").css("display", "none");
				cartPriceBuilder();
				break;
			case "myAcco":
				listings();
				if ($("#frame-4_s-col-2").length > 0) {
					$("#frame-4_s").css("display", "block");
				}
				else	
					$("#frame-4_s").css("display", "none");
				break;
			case "?utm_s":
				topSellers("home");
				listings();
				if ($("#frame-4_s-col-2").length > 0) {
					$("#frame-4_s").css("display", "block");
				}
				else	
					$("#frame-4_s").css("display", "none");
				break;
			default: 
				overlay("details");
				topSellers("details");
				listings();
				details();
				break;
		}
	}	
	
	
	$(".footer2").children("div:first").css({
		"textAlign":"right",
		"position":"relative",
		"width":"996px",
		"margin":"0 auto",
		"top": "11px"
	}).children("img").removeAttr("style")
		.parent().next(".copyright_footer").css({
			"fontSize": "11px",
			"position": "relative",
			"top": "-24px",
			"paddingTop":"0px",
			"lineHeight":"14px"
		});
		
	/* Refresh Changes */
	// Recent Items LIST PRICE STRIKETHROUGH > Append the Price
	var recentlyViewedItem = $("#frame-4_s .thirtyseven");
	//var prices = $(this).children("h5").text();
	$(recentlyViewedItem).each(function() {
		var price = $(this).children("h5").text().replace(new RegExp( "\t", "g" ),"").split("\n");
		if ($.browser.msie) {
			var price = price[0].split(" ");
			var nolist = '';
			if (price[0] == 'Our')
				nolist = 'true';
			var price1 = price[2].split("O");
			var list = price1[0];
			var title = $(this).children(".titleWrapper");
			if (price1[0]) {
				if (nolist != 'true') {
					var price2 = price[4].split("Y");
					$(this).append("<h5 style='display:inline;'>Price: " + price2[0] + "</h5>");
					//$(this).append("<h5 style='color:#bd0e0b;display:inline;'>" + price2[0] + "</h5>");
				}
			}
			else {
				$(this).append("<h5>Price: " + price1[0] + "</h5>");
			}
			$(this).children("h5:first").hide();
		}
		else {
			if (price[1] == 'Our Price:') {
				var title = $(this).children(".titleWrapper");
				$("<h5 class='newprice'>Price: " + price[2] + "</h5>").insertAfter($(title));
				$(this).children("h5:last").hide();
			}
			else {
				var list = price[2];
				var our = price[4];
				var title = $(this).children(".titleWrapper");
				$("<h5 class='newprice'>Price: " + our + "</h5>").insertAfter($(title));
				$(this).children("h5:last").hide();
			}
		}
	});
	if ($.browser.msie) {
		$("#frame-4_s .buttonWrapper").css("marginTop", "15px");
	}
	
	//Change add to cart links
	$("#frame-3_s .itemBin, #frame-4_s .itemBin, #frame-3 .itemBin, #content-17 .itemBin, #content-18 .itemBin, #content-15 .itemBin").each(function() {
		var href = $(this).children(".imageWrapper").children("a").attr("href");
		if ($(this).children(".buttonWrapper").children("a").text() == 'more info') {
			$(this).append($("<a href='" + href + "' style='position:relative; top:-3px; left:85px;'><img src='http://shop.southparkstudios.com/images/spbtnaddtocart.png'></a>"));
		}
		else {
			$(this).children(".buttonWrapper").children("a").attr("href", href);
		}
	});
	var href = $("#frame-2 .mainWrapper .imageLink").attr("href");
	$("#frame-2 .mainWrapper .mainButtonWrapper").children("a").attr("href", href);
	
	/* Refresh Changes - Top Sellers */
	$("#frame-3_s .thirtyfour ").each(function() {
		var href = $(this).children(".imageWrapper").children("a").attr("href");
		var price = $(this).children("h5");
		$(price).append($("<span>&nbsp;|&nbsp;<a href='" + href + "'><img src='http://shop.southparkstudios.com/images/spbtnaddtocartshort.png' style='position:relative; top:3px;'></a></span>"));
	});
}

function category() {
	categorySetter();
	//if (window.location.href != 'http://shop.southparkstudios.com/category/41498294561/2/Apparel.htm')
	$(".productRowWrapper").children().children().each(function(i) {
		var thisHtml = $(this).html();
		//alert($(this).parent().parent().children().length); die;
		// If there is one result item or less
		if ($(this).parent().parent().children().length <= 1) {
			switch (lastClass($(this))) {
				case "contentImageWrapper":
					$(".categoryWrapper").append("<div class='fortyeight itemBin" + i + "'></div>").children(".itemBin" + i).append("<div class='listingImage'>" + thisHtml + "</div>");
					break;
				case "contentTitleWrapper":
					$(".itemBin" + (i - 1)).append(thisHtml);
					break;
				case "product-price":
					$(".itemBin" + (i - 2)).append("<h5>" + thisHtml + "</h5>");
					break;
			}
		}
		else {
			switch (lastClass($(this))) {
				case "contentImageWrapper":
					$(".categoryWrapper").append("<div class='fortyeight itemBin" + i + "'></div>").children(".itemBin" + i).append("<div class='listingImage'>" + thisHtml + "</div>");
					break;
				case "contentTitleWrapper":
					$(".itemBin" + (i - 3)).append(thisHtml);
					break;
				case "product-price":
					$(".itemBin" + (i - 6)).append("<h5>" + thisHtml + "</h5>");
					break;
			}
		}
		
	});
	
	$(".categoryWrapper").append("<div style='clear:both'></div>").children("tbody:first").remove();
	$(".fortyeight br").remove();
	$(".categoryFeaturedLine").remove();
	
	$(".thirtyseven").css({"width": "307px", "top":"3px"})
		.children(".titleWrapper").css({"top":"8px", "left":"122px", "width": "182px", "height":"90px"})
		.siblings("h5").css({"top":"7px", "left":"122px", "width":"182px"})
		.siblings(".buttonWrapper").css({"top":"57px", "left":"122px", "width":"182px"});
	$(".wba_contentright").append($(".categoryWrapper"));
	
	$(".mainWrapper").addClass("fortynine")
		.append("<h5 class='categoryName'>"+$(".crumbPast:last").text()+"</h5>")
		.append($(".mainImageWrapper a"))
		.append($(".mainHeaderWrapper"))
		.append($(".mainPriceWrapper span"))
		.append($(".mainButtonWrapper").parent())
		.children("table").remove();
	$(".mainWrapper")
		.children(":first").next().addClass("imageLink")
		.siblings(":last").addClass("button")
		.siblings("span").html($(".mainWrapper").children("span").text())
		.siblings(".bold-price").remove();
	
	$("body").append($(".footer2"));
	$("#postpage-widget_s").closest("table").remove();
	$(".bodyWrapper").append($(".categoryWrapper"));
	
	var pageParent = $("#leftcol #leftcol-col-1 a:last").parent();
	$("<div class='ninetysix'></div>").insertAfter($(".fortyeight:last").next());
	$(".ninetysix")
		.append("<h5>Page: </h5>")
		.append($(pageParent).children())
		//Refresh change
		.children("a").css({"fontSize":"14px", "textDecoration": "underline"});
	$(".ninetysix a:contains('Shop South Park')").parent().hide();
	$(".eighty").insertBefore($("#frame-3_s"));
	
	$(".wba_contentright").children().wrapAll("<div class='ninetyseven'></div>");
	$(".bodyWrapper").append($(".ninetyseven"));

	$(".thirtyseven").css("width", "295px");
	$(".fifteen").css("top", "21px");
	
	if ($("h5.categoryName").text() == 'DVDs') {
		$(".thirtyseven").css("top", "3px");
	}
	else {
		$(".thirtyseven").css("top", "25px");
	}
	
	if ($("h5.categoryName").text() != 'DVDs' && $("h5.categoryName").text() != 'Toys & Games' && $("h5.categoryName").text() != 'Cartman') {
		$("#frame-2").css("marginTop", "100px");
	}
	
	var catimage = $(".mainWrapper").children("a").children("img:first");
	//Resize top image
	$(catimage).each(function() {
		var w = parseInt($(this).css("width"));
        var h = parseInt($(this).css("height"));
        var changed = false;

        if ( w > 132 ) {
            var f = 1 - ((w - 132) / w);
            w = w * f;
            h = h * f;
            changed = true;
        }
        
        if ( h > 175 ) {
            var f = 1 - (( h - 175) / h);
            w = w * f;
            h = h * f;
            changed = true;
        }
        
        if ( changed = true) {
            $(this).css("width", w);
            $(this).css("height", h);
        }
	});
	
	if($(".ninetysix").children(":first").next().text() == '1' || $(".ninetysix").children(":first").next().text() == '<< prev')
		$(".ninetysix").css("display", "block");
	else 
		$(".ninetysix").css("display", "none");
	
	$(".fortynine").append($(".eightyseven"));
	$(".eightyseven").parent().css("textAlign", "left").removeClass("button");
	
	$(".attribution").css("display", "none").prev("br").css("display", "none");
	
	$(".sixteen .twentyfour:contains('next >>')").css("display", "none");
	
	//Truncate smaller titles
	$(".fortyeight a.product-title").each(function() {
		var str = $(this).text();
		var limit = 50;
		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);
	});
	
	/*if ($("h5.categoryName:contains('CDs'))")) {
		alert($(".breadCrumbWrapper").html());
		$(".breadCrumbWrapper").children(":nth-child(3)").css("display", "none");
	}*/
	
	/*Refresh Changes*/
	
	//Insert header above dvd listings
	var catheader = $("h5.categoryName").text();
	$(".categoryWrapper").prepend("<div class='ninetynine catlistheader'>All " + catheader + "</div>");
	if ($.browser.msie) {
		if ($.browser.version <= '7.0') {
		
		}
	}
	//hr below main header
	$("<hr class='headerhr'>").insertAfter($("h5.categoryName"));
	//Add add to cart to second featured products widget
	$("#frame-3 .featuredproductsTitle").each(function() {
		var href = $(this).children().attr("href");
		var parent = $(this).parent();
		$(parent).append($("<a href='" + href + "' style='position:relative; top:10px; left:122px;'><img src='http://shop.southparkstudios.com/images/wba_add_to_cart_btn_med.gif'></a>"));
	});
	//Add add to cart to product listing widget
	$(".categoryWrapper .product-title").each(function() {
		var href = $(this).attr("href");
		var parent = $(this).parent();
		$(parent).append($("<a href='" + href + "' style='position:relative; top:-3px; left:82px;'><img src='http://shop.southparkstudios.com/images/spbtnaddtocart.png'></a>"));
	});
	$("#frame-3 .productSectionLabel").hide();
	//$("<hr class='eightythree categoryFeaturedLine'>").insertBefore($("#frame-3").children().children().children(".fifteen"));
	//$("<hr class='eightyeight categoryProductsLine'>").insertBefore($(".categoryContentWrapper:first"));
	//Replicate page numbers on bottom
	$(".ninetysix").clone().appendTo($(".categoryWrapper"));
	$(".ninetysix:last").css("top", "570px");
	
	/*if ($("div.itemBin27 h5").html() == null) {
		if (wba_category.product[10].listPrice)
			$("<h5>" + wba_category.product[10].listPrice + "</h5>");
	}*/
	/*if ($("div.itemBin28 a.product-title").html() == null) {
		$("div.itemBin28").append("<a href='" + wba_category.product[11].productDetailUrl + "' class='product-title' style='color:#0F3297;'>" + wba_category.product[11].title + "</a>");
		alert(wba_category.product[10].title);
	}*/
}

function categorySetter() {
	$("#frame-3_s").css({
		"top": "35px",
		"left":"807px",
		"position":"absolute",
		"width":"189px"
	});
	$("#leftcol-col-21").children().wrap("<div class='eighty categoryWrapper'></div>");
	$("h1").parent().parent().next().next().children().children(":first").wrap("<div class='eightyone categoryContentWrapper'></div>");
	$(".content").children().wrap("<div class='eightytwo bodyWrapper'></div>");
	$("#frame-2").children().children().children("div").children().wrap("<div class='mainWrapper'></div>");
	$(".mainWrapper").children().children().children().next().children().next().children("table").wrap("<div class='mainContentWrapper'></div>");
	$(".mainContentWrapper").children().children().children().next().children("td:first").addClass("eightyfour mainImageWrapper").next().children().wrap("<div class='eightyfive mainHeaderWrapper'></div>");
	$(".mainHeaderWrapper").children().css("fontSize", "20px");
	$(".mainImageWrapper").parent().next().next().children().children().wrap("<div class='eightysix mainPriceWrapper'></div>");
	
	$("span.bold-price").css("fontSize", "20px");
	$("span.bold-price").parent().next().children().wrap("<div class='eightyseven mainButtonWrapper'></div>");
	$(".mainButtonWrapper img").attr("src", "http://southparkstudios.amazonwebstore.com/images/btn_addtocart_black.jpg");
	$(".productSectionLabel").css("fontSize", "18px");
	$("#frame-3 div.titleWrapper").children().css("fontSize", "14px");
	$("#frame-3 h5").css("fontSize", "14px");
	//Refresh change
	$("#frame-3 .imageWrapper").children().children("img").removeAttr("height").removeAttr("width").css({"maxWidth":"105px", "width":"auto", "height":"auto"});
	
	$(".categoryContentWrapper").children().children().children().children().css("textAlign", "left").css("verticalAlign","top").children().children("img").parent().wrap("<div class='eightynine contentImageWrapper'></div>");
	$(".categoryContentWrapper").children().children().children().addClass("ninetyone productRowWrapper");
	$(".contentImageWrapper").children().children("img").removeAttr("height").removeAttr("width").css("maxWidth", "76px");
	$(".contentImageWrapper").parent().parent().next().children().children().addClass("ninety contentTitleWrapper");
	$(".product-title").css("color", "#0f3297");
	$(".categoryContentWrapper").next().wrap("<div class='ninetytwo pageWrapper'></div>");
	$("[src*='page_next.gif']").parent().css("textDecoration", "none").html("next >>");
	$("[src*='page_prev.gif']").parent().css("textDecoration", "none").html("<< prev");
	//$(".categoryWrapper").children().children().children(":nth-child(3)").children().wrap("<div class='seventyone categoryContentWrapper'></div>");
}

function details() {
	// Add more specific markup to page 
	detailsSetter();
	$("#frame-3").addClass("fortytwo").css({
		"position": "relative",
		"left":"-147px",
		"top":"40px"
	});
	$(".content").prepend($(".productWrapper"));
	$(".productWrapper")
		.prepend($(".productWrapper .productInformationWrapper"))
		.prepend($(".productWrapper .productDetailsWrapper"))
		.prepend($(".productWrapper .productImageWrapper"))
		.append($(".fortytwo"))
		.append($("#frame-3_s"))
		.children("#frame-3_s").css({
			"top":"-21px",
			"position": "absolute",
			"zIndex":1000,
			"left": "613px"
		}).children("table").remove();
	
	$("body").append($(".footer2"));
	
	$(".productDetailsWrapper")
		.append($(".productDetailsWrapper h1:first"))
		.append($(".wbaProductRatingWidget"))
		.append($(".productPricingWrapper"))
		.append($("#inStock"))
		.append($("#parentAvailability"))
		.append($(".addToCart"));
	
	$(".productDetailsWrapper table input, .productDetailsWrapper select").each(function() {
		$(".addToCart").prepend($(this)).append($(this).siblings());
	});
	$("#addToCart").append($("#addToCart").siblings())
		.css("zIndex", 1000)
		.children(".wba_add_to_cart_btn:first").attr("src", "http://southparkstudios.amazonwebstore.com/images/btn_addtocart_black.jpg")
		.siblings("select").css({"position":"absolute", "top": "-40px"})
		.siblings(".wba_add_to_cart_btn:last").remove();
	
	$(".addToCart").children("img").remove();
	$(".productDetailsWrapper").children("table").remove();
	$(".productDetailsWrapper").children(":not(':first')").wrapAll("<div class='fortyone'></div>");
	
	$(".productImageWrapper").append($("#productImage").parent())
		.children("table:first").remove();
	$(".productWrapper").next().wrap("<div class='thirtynine'></div>");
	$(".productShipping").css({
		"fontSize":"13px",
		"fontWeight": "bold"
	});
	
	if ($("span#parentAvailability").text() == "Out of stock") {
		$(".addToCart").css("display", "none");
	}
	
	// To be implemented later to fix IE problem with shipping size
	$(".productPricingWrapper").append("<div class='fortythree priceBin'></div>");	
	$(".productPricingWrapper td").each(function(i) {
		if (i<6) {
			if ((i%2)==0) {
				$(".priceBin").append("<div class='fortyfour priceItem'></div>");	
			}
			// Check if this price has more than 1 charachter
			if ($(this).text().length>1) {
				// Add this string as an <h5> to the most recently added $(".priceItem")
				$(".priceBin").children(".priceItem:last").append("<h5>"+$(this).text()+"</h5>");
			} else {
				// Hide the most recently added $(".priceItem")
				$(".priceBin").children(".priceItem:last").hide();
			}
		} else {
			switch(i) {
				case 6:
					$(".priceBin").append("<h5 class='fortyfive'>"+$(this).html().replace("*", "")+"</h5>");
					break;
				case 7:
					$(".priceBin").append("<h5 class='fortysix>This item ships for <b>FREE with Super Saver Shipping</b>.</h5>");
					break;
			}
		} 
	});
	$(".priceBin").children(".priceItem:first").children("h5:last").wrapInner("<s></s>");
	
	//$("#leftcol-col-258").css("height", "56px");
	//$("[id*='leftcol-col-251']").css("height", "67px");
	/*alert($("[id*='leftcol-col-25']:not(':first')").html());
	$("<hr>").insertBefore($("[id*='leftcol-col-25']:not(':first').children('strong')"));*/
	
	$("#features").prev().remove();
	$("#features").next().next().remove();
	$("#leftcol-col-253, #leftcol-col-256, #features").remove();
	$(".productPricingWrapper").children(":first").remove();
	$("#shippingDisclaimer").closest("table").remove();
	
/*
	var action = $(".addToCart form").attr("action");
	$("<a href='" + action + "'><img class='wba_add_to_cart_btn' title='Add to Cart' src='http://southparkstudios.amazonwebstore.com/images/btn_addtocart_black.jpg' alt='Add to Cart'></a>").insertAfter($(".fortyone .addToCart input.wba_add_to_cart_btn"));
	$("<a href='" + action + "' style='position:relative; top:10px;'>\
			<img class='wba_add_to_cart_btn' title='Add to Cart' src='http://southparkstudios.amazonwebstore.com/images/btn_addtocart_black.jpg' alt='Add to Cart'>\
		</a>").insertAfter($(".fortyone .addToCart img.wba_add_to_cart_btn"));
	$(".addToCart input.wba_add_to_cart_btn").hide();
	$(".addToCart img.wba_add_to_cart_btn:first").hide();
*/
	
	// RELATED ITEMS
	$(".relateditems .thirtyseven").each(function() {
		var theClasses = $(this).attr("class").split(" ");
			$(this).attr("class", "ninetyfive "+theClasses[1]+" "+theClasses[2]);
	});
	
	$("#toyWarnings strong:contains('CHOKING HAZARD')").css("top", "0px").css("fontSize", "14px");
	
	$(".breadCrumbWrapper").css("top", "55px");
	$("#leftnav-1_s").css("top", "72px");
	
	$("<hr class='hr_product'>").insertBefore($("[id*='leftcol-col-25']").children("strong:not(':first')"));
	$("[id*='leftcol-col-25']").children("strong").parent().css("paddingBottom", "15px");
	
	$("form#addToCart").children("img").css("display", "none");
	$("form#addToCart [src*='spbtnaddtocart.png']:first").attr("src", "http://southparkstudios.amazonwebstore.com/images/btn_addtocart_black.jpg");
	$("[src*='btn_addtocart_lg.gif']").attr("src", "http://southparkstudios.amazonwebstore.com/images/btn_addtocart_black.jpg");
	
	if ($.browser.msie) {
		if($.browser.version == '7.0') {
			$("<a href='javascript:' onclick='document.addToCart.submit()' class='iebutton'><img border=0 src='http://southparkstudios.amazonwebstore.com/images/btn_addtocart_black.jpg'></a>").insertBefore($(".fiftysix"));
		}
	}
	
	/*
		// Pull out elements from the child tables and append elements inside $(this).parent("div") , .productInformationWrapper td
		$(".productDetailsWrapper td, .productPricingWrapper td").each(function() {
			
			// Closest div with product in class name
			var thisParent = $("."+lastClass($(this).closest("div[class*='product']")));
				// Append this child to the closest $(thisParent)
				$(thisParent).append($(this).html());
	
		});
		// After moving elements to $(".productDetailsWrapper") remove their old parent table
		$(".productDetailsWrapper").children("table").remove();
		$(".productWrapper").append($(".productDetailsWrapper"));
	*/
	$("#frame-3 .itemBin h5").prepend("Price: ");
}

function detailsSetter() {
	$("#parentAvailability").wrap("<div style='position:relative; top:0px'></div>");
	$("a:contains('Email')").hide().siblings().hide();
	$("a:contains('Zoom')").hide().siblings().hide();
	$("#leftcol-col-25").children("table:first").wrap("<div class='fifty productWrapper'></div>");
	$("#leftcol-col-251").children("table").wrap("<div class='fiftyone productImageWrapper'></div>");
	$("#leftcol-col-252").children("table").wrap("<div class='fiftytwo productDetailsWrapper'></div>");

	$(".wba_add_to_cart_btn:first").parent().children().wrapAll("<div class='forty addToCart'></div>");
	$(".forty")
		.prepend($("#popUpImageUrl"))
		.prepend($("form#addToCart"));
	$(".addToCart").children("input:first").attr("src", "http://southparkstudios.amazonwebstore.com/images/btn_addtocart_black.jpg")
		.removeAttr("style");
	$(".buttonWrapper div.forty").removeClass("forty");
	
	//Keep alternate views
	if ($("#variant_0")) {
		$("#variant_0").parent().parent().parent().parent().wrap("<div class='productAltView'></div>");
		$(".productAltView").insertAfter($(".fiftyone a:last"));
	}
	
	//Place Size dropdown
	$(".fiftytwo").append($("#Size"));
	$("#Size").wrap("<div style='position:absolute; bottom:-8px; left:222px;'></div>");
	//$("#Size").insertAfter($("#parentAvailability"));
	
	$("#leftcol-col-1").children("table").wrap("<div class='fiftythree breadcrumbWrapper'></div>");
	$(".list-label").parent().parent().parent().wrap("<div class='fiftyfour productPricingWrapper'></div>");
	$(".save-label").parent().next("tr").children("td").addClass("fiftyfive productShipping");
	$(".fiftyfive:last").css("width", "240px");
	$(".tiny b").remove();
	$(".productDetailsWrapper").children().children().children(":nth-child(15)")
		.children().children("input:first").css({
			"position": "relative",
			"left": "-4px",
			"top": "14px"
		});
	$(".productDetailsWrapper").children().children().children(":nth-child(16)").children().children("input:first").attr("src", "http://southparkstudios.amazonwebstore.com/images/btn_addtocart_black.jpg").css("position", "relative").css("left", "-2px"). css("top", "30px");
	$(".productInformationWrapper").children("table:first").children().children().children().children("strong").css("fontWeight", "bold").css("fontSize", "18px");
	$("[id*='leftcol-col-25'] strong").css("fontWeight", "bold").css("fontSize", "18px").css("color", "black");
	$("#leftcol-col-254 strong").css("fontWeight", "bold").css("fontSize", "18px");
	$("#leftcol-col-258 strong").css("fontWeight", "bold").css("fontSize", "18px");
	$("#leftcol-col-2512 strong").css("fontWeight", "bold").css("fontSize", "18px");
	$("#leftcol-col-2516 strong").css("fontWeight", "bold").css("fontSize", "18px");
	$("#leftcol-col-254").parent().parent().parent().wrap("<div class='fiftysix productInformationWrapper'></div>");
	$(".productSectionLabel b").css("fontSize", "18px");
	//$("#frame-3").wrap("<div style='position:relative; height:246px;'></div>");
	
	$("#shippingMainLabel").parent().children().css("height", "30px");
}

// Formats these listing types > New Products, Featured Products, DVDs, Recently Viewed Items
function listings() {
	$("body").data("itemCount", 0);
	$(".sixteen .productItemBin").children("td").children("div").each(function() {	
		var lastClass = $(this).attr("class").split(" "),
			lastClassLength = lastClass.length-1,
			thisParent = $(this).closest(".sixteen"),
			thisLabel = $(this).parent().attr("class").split(" ");
		
		$("body").data("itemName", thisLabel[thisLabel.length-1]);
		
		switch(lastClass[lastClassLength]) {
			case "imageWrapper":
				$("body").data("itemCount", $("body").data("itemCount")+1);
				
				$(thisParent).append("<div class='thirtyseven itemBin "+ $('body').data('itemName')+"Item"+$("body").data("itemCount")+"'></div>");		
				$("."+$('body').data('itemName')+"Item"+$("body").data("itemCount")).append($(this));			
				break;
			case $('body').data('itemName')+"Title":
				$("."+$('body').data('itemName')+"Item"+$("body").data("itemCount")).append($(this));	
				break;
		}
	});
	
	$("body").data("moneyCount", 0);
	$(".sixteen .productMoneyRow").children("td").children("div").each(function() {
		var thisMoney = $(this).children("table").children().children(),
		thisLabel = $(this).parent().attr("class").split(" ");
		
		$("body").data("itemName", thisLabel[thisLabel.length-1]);
		$("body").data("moneyCount", $("body").data("moneyCount")+1);
		
		$("."+$('body').data('itemName')+"Item"+$("body").data("moneyCount")).append($(thisMoney).children().children());
	});
	$(".sixteen").css("padding", "0px");
	$(".sixteen table").remove();
	$(".sixteen itemBin").append("<div style='clear:both'></div>");
	
	var image = $(".imageWrapper").children("a").children("img");
	//Resize images for listings
	$(image).each(function() {
		
			var w = parseInt($(this).css("width"));
			var h = parseInt($(this).css("height"));
			var changed = false;
			
			if (w > 76) {
				var f = 1 - ((w - 76) / w);
				w = w * f;
				h = h * f;
				changed = true;
			}
			
			if (h > 100) {
				var f = 1 - ((h - 100) / h);
				w = w * f;
				h = h * f;
				changed = true;
			}
			
			if (changed = true) {
				$(this).css("width", w);
				$(this).css("height", h);
			}
		
	});
	
	//Truncate Title to two lines
	//$('.twentysix a').truncatable({limit: 50, more: '...', less: false});
	
	$(".twentysix a").each(function() {
		var str = $(this).text();
		var limit = 50;
		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);
	});
	 
	
	
	$("#frame-4_s-col-3").addClass("thirtyeight");
}


// TOP Sellers
function topSellers(thisPage) {
	switch (thisPage) {
		case "home":
			topSellersHome();
			break;
		case "details":
			topSellersDetails();
			break;
		case "apparel":
			topSellersApparel();
			break;
		case "cart":
			topSellersCart();
			break;
	}
}

function topSellersApparel(){

}

function topSellersCart () {
	// Add top sellers image with rounded corners above top seller items
	$(".thirty").prev().css({
		"background": "url('http://southparkstudios.amazonwebstore.com/images/spbgalsoliketp.jpg') no-repeat scroll left top transparent",
		"width": "100%"
	});
	// Add parent positioning class > use this class to set the top sellers position from left and top of page

	//$(".topSellersWrapper").append($("#frame-3_s-2"));
	/*$(".thirtyone .productItemBin, .thirtyone .productMoneyRow").children("td").each(function(i) {
		var lastClass = $(this).children().attr("class").split(" "),
			lastClassLength = lastClass.length-1
			thisObject = $(this).children();
		switch(lastClass[lastClassLength]) {
			case "imageWrapper":
				$(".topSellersWrapper").append("<div class='thirtyfour topSellerItem"+i+"'></div>");	
				$(".topSellerItem"+(i)).append($(thisObject));	
				break;
			case "topsellersTitle":
				$(".topSellerItem"+(i-1)).append($(thisObject));
				break;
			case "productMoneyWrapper":
				//$(".topSellerItem"+(i-2)).append($(thisObject).children("table").children().children().children().children("h5"));
				var thisMoney = $(thisObject).children("table").children().children();
				
				// LIST PRICE STRIKETHROUGH > Append the Price
				var topSellerItem = $(".topSellerItem"+(i-2));
				$(topSellerItem).data("prices", $(thisMoney).children(":first").children("h5").text())
				
				// topSellerItem represents bin containing each item's details.
				priceBuilder(topSellerItem);
				$(".thirtyfour").css("textAlign", "center");
				$(".thirtyfour h5").css("display", "inline").css("top", "11px").css("marginRight", "4px");
				break;
		}
	});*/
	$("#frame-6 .thirtyseven").each(function() {
		var parent = $(this).parent().parent();
		$(parent).append($(this));
	});
	
	// Add rounded ending background to top sellers :last item and add 10px of bottom padding to match up with design
	$(".thirty").children(":last").css({
		"background": "transparent URL('http://southparkstudios.amazonwebstore.com/images/spbgtopsellerproductbtm.jpg') no-repeat bottom left",
		"paddingBottom":"30px",
		"border":"1px solid transparent",
		"backgroundPosition": "-1px 130px",
		"marginBottom":"-27px"
	});
	
	$(".thirtyfour h5").text();
	$("#frame-6_s-2").text("");
	// Remove Add to Card button from top sellers pane on product details page
	//$(".topSellersWrapper .productOrderButton").remove();	
	//$("#frame-6_s-3").hide();
}

function topSellersHome(){
	// Add top sellers image with rounded corners above top seller items
	$(".thirty").prev().css({
		"background": "black URL('http://southparkstudios.amazonwebstore.com/images/spbgtopsellertp.png') no-repeat top left",
		"width": "250px"
	// Add parent positioning class > use this class to set the top sellers position from left and top of page
	}).parent().parent().parent().addClass("thirtysix");
	
	//$(".topSellersWrapper").append($("#frame-3_s-2"));
	$(".thirtyone .productItemBin, .thirtyone .productMoneyRow").children("td").each(function(i) {
		var lastClass = $(this).children().attr("class").split(" "),
			lastClassLength = lastClass.length-1
			thisObject = $(this).children();
		switch(lastClass[lastClassLength]) {
			case "imageWrapper":
				$(".topSellersWrapper").append("<div class='itemBin topSellerItem"+i+"'></div>");	
				$(".topSellerItem"+(i)).append($(thisObject));	
				break;
			case "topsellersTitle":
				$(".topSellerItem"+(i-1)).append($(thisObject));
				break;
			case "productMoneyWrapper":
				var thisMoney = $(thisObject).children("table").children().children();
				
				// LIST PRICE STRIKETHROUGH > Append the Price
				var topSellerItem = $(".topSellerItem"+(i-2));
				$(topSellerItem).data("prices", $(thisMoney).children(":first").children("h5").text())
				// Append the "add to cart" button
					.append($(thisMoney).children(":first").next().children("div"));
				
				// topSellerItem represents bin containing each item's details.
				priceBuilder(topSellerItem);
				break;
		}
	});
	
	// Add rounded ending background to top sellers :last item and add 10px of bottom padding to match up with design
	$(".thirty").attr("class", "thirtyfive topsellersWrapper").children(":last").css({
		"background": "transparent URL('http://southparkstudios.amazonwebstore.com/images/spbgtopsellerbtm.png') no-repeat bottom left",
		"backgroundPosition":"-2px 135px",
		"paddingBottom":"38px",
		"marginBottom":"-22px",
		"borderLeft":"1px solid transparent"
	});
	
	// Remove Add to Card button from top sellers pane on product details page
	//$(".topSellersWrapper .productOrderButton").remove();	
	$("#frame-3_s-3").remove();
}

function topSellersDetails() {
	// Add top sellers image with rounded corners above top seller items
	$(".thirty").prev().css({
		"background": "url('http://southparkstudios.amazonwebstore.com/images/spbgtopsellerproducttp.jpg') no-repeat scroll left top transparent",
		"width": "100%"
	// Add parent positioning class > use this class to set the top sellers position from left and top of page
	}).parent().parent().parent().css({
		"top": "-38px",
		"position":"relative",
		"width": "189px",
		"left":"647px"
	});
	//$(".topSellersWrapper").append($("#frame-3_s-2"));
	$(".thirtyone .productItemBin, .thirtyone .productMoneyRow").children("td").each(function(i) {
		var lastClass = $(this).children().attr("class").split(" "),
			lastClassLength = lastClass.length-1
			thisObject = $(this).children();
		switch(lastClass[lastClassLength]) {
			case "imageWrapper":
				$(".topSellersWrapper").append("<div class='thirtyfour topSellerItem"+i+"'></div>");	
				$(".topSellerItem"+(i)).append($(thisObject));	
				break;
			case "topsellersTitle":
				$(".topSellerItem"+(i-1)).append($(thisObject));
				break;
			case "productMoneyWrapper":
				//$(".topSellerItem"+(i-2)).append($(thisObject).children("table").children().children().children().children("h5"));
				var thisMoney = $(thisObject).children("table").children().children();
				
				// LIST PRICE STRIKETHROUGH > Append the Price
				var topSellerItem = $(".topSellerItem"+(i-2));
				$(topSellerItem).data("prices", $(thisMoney).children(":first").children("h5").text())
				
				// topSellerItem represents bin containing each item's details.
				priceBuilder(topSellerItem);
				$(".thirtyfour").css("textAlign", "center");
				$(".thirtyfour h5").css("display", "inline").css("top", "11px").css("marginRight", "4px");
				break;
		}
	});
	
	// Add rounded ending background to top sellers :last item and add 10px of bottom padding to match up with design
	$(".thirty").children(":last").css({
		"background": "transparent URL('http://southparkstudios.amazonwebstore.com/images/spbgtopsellerproductbtm.jpg') no-repeat bottom left",
		"paddingBottom":"20px",
		"border":"1px solid transparent",
		"backgroundPosition": "-1px 130px",
		"marginBottom":"-27px"
	});
	
	$(".thirtyfour h5").text();
	
	// Remove Add to Card button from top sellers pane on product details page
	//$(".topSellersWrapper .productOrderButton").remove();	
	$("#frame-3_s-3").remove();
}

function cartPriceBuilder () {
	$("#frame-6 .thirtyseven h5").each(function() {
		var price = $(this).text().replace(new RegExp( "\t", "g" ),"").split("\n");
		var parent = $(this).parent();
		if ($.browser.msie) {
			var price = price[0].split(" ");
			var price1 = price[2].split("O");
			var our = price1[0];
			//alert(price1[0]);
			if (price1[0]) {
				if (price[4]) {
					var price2 = price[4].split("Y");
					$(parent).append("<h5>Price: " + price2[0] + "</h5>");
					//$(thisObject).append("<h5 style='color:#bd0e0b'>" + price2[0] + "</h5>");
				}
				else {
					$(parent).append("<h5>Price: " + price1[0] + "</h5>");
				}
			}
		}
		else {
			/*$.each(price, function(i){
				switch (price[i].toLowerCase()) {
					case "list price:":
						
						$(parent).append("<h5>Price: " + price[i + 3] + "</h5>");
						break;
					case "our price:":
						// Sometimes amazon only returns our price and not the list price
						// If there are no <h5> children
						if ($(parent).children("h5").length < 1) {
							// Append "Price: " to the value and don't make red
							$(parent).append("<h5>Price: " + price[i + 3] + "</h5>");
						}
						//else {
							// Append value with red
							//$(thisObject).append("<h5 style='color:#bd0e0b'>" + price[i + 1] + "</h5>");
						//}
						break;
				}
			});*/
			if (price[1] == 'List Price:') {
				$(parent).append("<h5>Price: " + price[4] + "</h5>");
			}
			else if(price[1] == 'Our Price:') {
				$(parent).append("<h5>Price: " + price[2] + "</h5>");
			}
		}
		$(this).hide();
		var href = $(this).parent().children(".imageWrapper").children("a").attr("href");
		$(parent).children("h5:last").append($("<span>&nbsp;|&nbsp;<a href='" + href + "'><img src='http://shop.southparkstudios.com/images/spbtnaddtocartshort.png' style='position:relative; top:3px;'></a></span>"));
	});
	$("#frame-6 .thirtyseven:last").css({
		"background": "transparent URL('http://southparkstudios.amazonwebstore.com/images/spbgtopsellerproductbtm.jpg') no-repeat bottom left",
		"paddingBottom":"20px",
		"border":"1px solid transparent",
		"backgroundPosition": "-1px 158px",
		"marginBottom":"-27px"
	});
	if ($.browser.msie || $.browser.safari) {
		$("#frame-6 .thirtyseven:last").css("backgroundPosition", "-1px 156px");
	}
	/*if ($.browser.safari || $.browser.webkit) {
		$("#frame-6").css("left", "1005px");
	}*/
	$(".content").css("minHeight", "860px");
	$("#frame-5").css({"top":"250px", "marginBottom":"220px"});
}

function priceBuilder(thisObject) {
	// Strip out all line breaks.
	var price = $(thisObject).data("prices").replace(new RegExp( "\t", "g" ),"").split("\n");
	//alert(price[4]);
	if ($.browser.msie) {
		var price = price[0].split(" ");
		var price1 = price[2].split("O");
		var our = price1[0];
		//alert(price1[0]);
		if (price1[0]) {
			if (price[4]) {
				var price2 = price[4].split("Y");
				$(thisObject).append("<h5>Price: " + price2[0] + "</h5>");
				//$(thisObject).append("<h5 style='color:#bd0e0b'>" + price2[0] + "</h5>");
			}
			else {
				$(thisObject).append("<h5>Price: " + price1[0] + "</h5>");
			}
		}
		
		$.each(price, function(i){
			/*if (i = 0) {
				
			}
			else if (i = )
			
			switch (price[i].toLowerCase()) {
				case "list":
					
					$(thisObject).append("<h5>Price: <s>" + price1[0] + "</s></h5>");
					break;
				case "our":
					// Sometimes amazon only returns our price and not the list price
					// If there are no <h5> children
					if (price2) {
						// Append value with red
						$(thisObject).append("<h5 style='color:#bd0e0b'>" + price2[0] + "</h5>");
					}
					else {
						// Append "Price: " to the value and don't make red
						$(thisObject).append("<h5>Price: " + price1[0] + "</h5>");
					}
					break;
			}*/
		});
	}
	else {
		$.each(price, function(i){
			switch (price[i].toLowerCase()) {
				case "list price:":
					
					$(thisObject).append("<h5>Price: " + price[i + 3] + "</h5>");
					break;
				case "our price:":
					// Sometimes amazon only returns our price and not the list price
					// If there are no <h5> children

					if ($(thisObject).children("h5").length < 1) {
						// Append "Price: " to the value and don't make red
						$(thisObject).append("<h5>Price: " + price[i + 3] + "</h5>");
					}
					/*else {
						// Append value with red
						$(thisObject).append("<h5 style='color:#bd0e0b'>" + price[i + 1] + "</h5>");
					}*/
					break;
			}
		});
	}
}


function overlay(thisPage) {
	$(".overlayControl").live("click", function() {
		switch($(this).text()) {
			case "on":
				$(this).text("off");
				$(".overlayBin").fadeIn(600).animate({"opacity":.5}, 600);
				break;
			case "off":
				$(this).text("on");
				$(".overlayBin").fadeOut(600).animate({"opacity":0}, 600);			
				break;
		}
	});
	/*$("body").append("<h6 class='overlayControl'>on</h6>");
	
	switch(thisPage) {
		case "home":
			$("body").append("<div class='overlayBin'><img src='http://southpark.devtrigo.com/media/indexMock.jpg' class='overlay'></div>");
			break;
		case "details":
			$("body").append("<div class='overlayBin'><img src='http://southpark.devtrigo.com/media/SP_Amazom_PG3_DVD_Detail.jpg' class='overlay'></div>");
			break;
		case "category":
			$("body").append("<div class='overlayBin'><img src='http://southpark.devtrigo.com/media/SP_Amazom_PG2_DVDs.jpg' class='overlay'></div>");
			break;
	}*/
}

// Return the last class for $(thisObject)
function lastClass(thisObject) {
	var thisClasses = $(thisObject).attr("class").split(" ");
	return thisClasses[thisClasses.length-1]; 
}

function oldScripts() {
	$('.wba_contentright table:eq(0)').attr('id','leftcol');
	$('.wba_maintable td:eq(10)').attr('id','tohide');
	
	
	$("img").each(function(i){
			try{			
				if($(this).attr("src").indexOf("/themes/sport/variations/blue/images/dots_leftnav_foot.gif")!=-1) {
					$(this).hide();
				}  
	
	
	}catch(e){}
	    });
	
	$("img").each(function(i){
			try{			
				if($(this).attr("src").indexOf("corner_topleft.gif")!=-1) {
					$(this).hide();
				}  
	if($(this).attr("src").indexOf("corner_topright.gif")!=-1) {
					$(this).hide();
				}  
	if($(this).attr("src").indexOf("corner_botleft.gif")!=-1) {
					$(this).hide();
				}  
	if($(this).attr("src").indexOf("corner_botright.gif")!=-1) {
					$(this).hide();
				}  
	if($(this).attr("src").indexOf("img_footer_left.jpg")!=-1) {
					$(this).hide();
				}  
	if($(this).attr("src").indexOf("img_footer_right.jpg")!=-1) {
					$(this).hide();
				}  
	
	if($(this).attr("src").indexOf("1_pixel.gif")!=-1) {
					$(this).hide();
				}  
	
	
			}catch(e){}
	    });
	
	$("td").each(function(i){
			try{			
				if($(this).attr("background").indexOf("/themes/sport/variations/blue/images/bg_leftnav_foot.gif")!=-1) {
					$(this).attr('background', 'none');
				} 
	
	
			}catch(e){}
	    });
	$("td").each(function(i){
			try{			
				if($(this).attr("bgcolor").indexOf("#ffffff")!=-1) {
					$(this).attr('bgcolor', 'transparent');
				} 
	
	
			}catch(e){}
	    });
	
	

	
	$("td").each(function(i){
					$(this).css('padding', '0px');
	    });

	
	
	
	
	
	$("td").each(function(i){
			try{			
			
	if($(this).attr("background").indexOf("/themes/sport/variations/blue/images/bg_leftnav.jpg")!=-1) {
					$(this).attr('background', 'none');
				} 
	
			}catch(e){}
	    });
	
	
	
	
	$("table").each(function(i){
			try{			
				if($(this).attr("background").indexOf("bg_footer.gif")!=-1) {
					$(this).hide();
				}  
	
			}catch(e){}
	    });
	
	$("table").each(function(i){
			try{			
				if($(this).attr("bgcolor").indexOf("#ffffff")!=-1) {
					$(this).attr('bgcolor', 'transparent');
				} 
	
			}catch(e){}
	    });
	$("table").each(function(i){
			try{			
				
	if($(this).attr("cellspacing").indexOf("10")!=-1) {
					$(this).attr('cellspacing', '0');
				} 
	
			}catch(e){}
	    });
	
	
	$("table").each(function(i){
			try{			
				
	if($(this).attr("cellspacing").indexOf("5")!=-1) {
					$(this).attr('cellspacing', '0');
				} 
	
			}catch(e){}
	    });
	
	$("a").each(function(i){
			try{			
				
	if($(this).attr("style").indexOf("font-size: 14px;")!=-1) {
					$(this).attr('style', 'font-size: 12px;');
				} 
	
			}catch(e){}
	    });
	
	$("a").each(function(i){
			try{			
				
	if($(this).attr("style").indexOf("font-size: 14px; font-weight: bold; padding-top: 10px;")!=-1) {
					$(this).attr('style', 'font-size: 12px;');
				} 
	
			}catch(e){}
	    });
	
	
	
	
	$("table").each(function(i){
			try{			
				
	if($(this).attr("cellspacing").indexOf("5")!=-1) {
					$(this).attr('cellspacing', '0');
				} 
	
			}catch(e){}
	    });
	
	
	
	
	$("tr").each(function(i){
			try{			
	if($(this).attr("bgcolor").indexOf("#ffffff")!=-1) {
					$(this).attr('bgcolor', 'transparent');
				} 
			}catch(e){}
	    });
	
	
	
	
	
	$("div").each(function(i){
			try{			
				if($(this).attr("style").indexOf("padding: 3px; font-size: 16px;")!=-1) {
	$(this).attr('style', 'padding: 3px; font-size: 18px;');
					
				}  
			}catch(e){}
	    });
	
	$("a").each(function(i){
			try{			
				if($(this).attr("style").indexOf("font-size: 12px;")!=-1) {
	$(this).attr('style', 'font-size: 14px; font-weight:bold;');
					
				}  
	
			}catch(e){}
	    });
	
	$("#leftcol table").each(function(i){
			try{			
				if($(this).attr("bgcolor").indexOf("#ffffff")!=-1) {
	$(this).attr('bgcolor', 'transparent');
					
				}  
	
			}catch(e){}
	    });
	
/*
	$("td").each(function(i){
			try{			
				if($(this).attr("style").indexOf("padding: 5px;")!=-1) {
	$(this).attr('style', 'padding: 0px;');
					
				}  
	
			}catch(e){}
	    });
*/
	
	
	
	i=1;
		$('#frame-3_s').children().children().children().each( function(){
			$(this).attr('id','frame-3_s-' + i);
			i++;
		});
	
	i=1;
	$('#frame-6').children().children().each( function(){
			$(this).attr('id','frame-6_s-' + i);
			i++;
		});
	
	i=1;
		$('#leftcol').children().children().children().each( function(){
			$(this).attr('id','leftcol-col-' + i);
			//if ($(this).text() == "" || $(this).text().match(/^\s$/)) $(this).remove();
			i++;
		});
	
	i=1;
		$('#content-18').children().children().children().each( function(){
			$(this).attr('id','content-18-col-' + i);
			
			i++;
		});
	
	i=1;
		$('#content-15').children().children().children().each( function(){
			$(this).attr('id','content-15-col-' + i);
			
			i++;
		});
	
	
	
	i=1;
		$('#content-16').children().children().children().each( function(){
			$(this).attr('id','content-16-col-' + i);
			
			i++;
		});
	
	i=1;
		$('#frame-4_s').children().children().children().each( function(){
			$(this).attr('id','frame-4_s-col-' + i);
			
			i++;
		});
	
	
	$('#frame-4_s').children().attr('id','topsellfooter' + i);;
	
	
	j=1;
		$('#content-18-col-3').children().children().children().children().each( function(){
			$(this).attr('id','content-18-col-3-' + j);
			
			j++;
		});
	
	
	k=1;
		$('#wba_main').children().children().children().each( function(){
			$(this).attr('id','wba_main-table' + k);
			
			k++;
		});
	
	k=1;
		$('#leftnav-6').children().children().each( function(){
			$(this).attr('id','leftnav-6-table' + k);
			
			k++;
		});
	
	
	k=1;
		$('#leftnav-6-table1').children().each( function(){
			$(this).attr('id','leftnav-6-table1' + k);
			
			k++;
		});
	k=1;
		$('#leftnav-6-table13').children().children().children().children().each( function(){
			$(this).attr('id','leftnav-6-table13' + k);
			
			k++;
		});
	
	k=1;
		$('#leftcol-col-2').children().each( function(){
			$(this).attr('id','leftcol-col-2' + k);
			
			k++;
		});
	
	
	
	k=1;
		$('#leftcol-col-21').children().children().children().each( function(){
			$(this).attr('id','leftcol-col-2' + k);
			
			k++;
		});
	k=1;
		$('#leftcol-col-25').children().children().children().children().children().children().children().children().each( function(){
			$(this).attr('id','leftcol-col-25' + k);
			
			k++;
		});
}

