function getParameterByName( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return decodeURIComponent(results[1].replace(/\+/g, " "));
}

var isHomepage=false;
/*
window.onload = function(){

	var fn = function(){
		if (!isHomepage) return;
		$("#homeSplash").animate({ opacity: 0  }, 1000,"linear", function(){
	
		$("body").attr("class","");
		$("#content_area").css("visibility","visible");
		$("#header,#content,#footer").css("visibility","visible").animate({ opacity: 0  }, 0 ).animate({ opacity: 1  }, 1500 );} );
	}
	setTimeout(fn,2000);
}
*/


$(function(){

try{


/*
  _   _                                             
 | | | | ___  _ __ ___   ___ _ __   __ _  __ _  ___ 
 | |_| |/ _ \| '_ ` _ \ / _ \ '_ \ / _` |/ _` |/ _ \
 |  _  | (_) | | | | | |  __/ |_) | (_| | (_| |  __/
 |_| |_|\___/|_| |_| |_|\___| .__/ \__,_|\__, |\___|
                            |_|          |___/    
*/							

if (window.location.pathname.length<2 || window.location.pathname.toLowerCase().indexOf("/default.asp")==0){

	$("#content_area br").remove();
	$("#content_area").css("paddingBottom","20px");

}


/*


   ____                           _ 
  / ___| ___ _ __   ___ _ __ __ _| |
 | |  _ / _ \ '_ \ / _ \ '__/ _` | |
 | |_| |  __/ | | |  __/ | | (_| | |
  \____|\___|_| |_|\___|_|  \__,_|_
 */


$("div.wishpot_form").css("display","none");


// remove breadcrumbs

var sectionName = $("#content_area span:contains('You are here:')").nextAll("a").last().text();

var currentSection = "";
var currentSubSection = "";
var currentSubSubSection = "";
var productName = "";
var productDetailsTable = null;
/*
  ____                     _                           _         
 | __ ) _ __ ___  __ _  __| | ___ _ __ _   _ _ __ ___ | |__  ___ 
 |  _ \| '__/ _ \/ _` |/ _` |/ __| '__| | | | '_ ` _ \| '_ \/ __|
 | |_) | | |  __/ (_| | (_| | (__| |  | |_| | | | | | | |_) \__ \
 |____/|_|  \___|\__,_|\__,_|\___|_|   \__,_|_| |_| |_|_.__/|___/
                                                                 
*/
// get current section

var breadcrumbContainer = $("#content_area b:contains('You are here:')").parents("table").eq(0)

// in product details section
if (breadcrumbContainer.length==0 && $("#content_area .productnamecolorLARGE").length!=0){

	productName = $("#content_area form[name='MainForm'] font.productnamecolorLARGE").text();
	breadcrumbContainer = $("form[name='MainForm'] a:contains('Home')").parents("tr:eq(0)");
	productDetailsTable = $("#content_area font.productnamecolorLARGE").parents("table:eq(0)");
}

currentSection = breadcrumbContainer.find("a").eq(1).text().toLowerCase().replace(" ","");


/*
  _   _             
 | \ | | __ ___   __
 |  \| |/ _` \ \ / /
 | |\  | (_| |\ V / 
 |_| \_|\__,_| \_/  
                    
*/

if ($("#nav .subnav").length!=0){
	var currentSection = $("#nav .subnav").parents("li").eq(0).attr("class");
	
	currentSubSection = breadcrumbContainer.find("a").eq(1).text();
	
}
	var nav = $("#nav").detach();
	nav.find("img").remove();
	
// remove breadcrumbs
breadcrumbContainer.remove();




/*
   ____       _                         _          
  / ___| __ _| |_  ___  __ _  ___  _ __(_) ___ ___ 
 | |    / _` | __|/ _ \/ _` |/ _ \| '__| |/ _ | __|
 | |___| (_| | |_|  __/ (_| | (_) | |  | |  __|__ \
  \____|\__,_|\__|\___|\__, |\___/|_|  |_|\___|___/
                       |___/                       


*/
// extract categories

var catsTable = $("#content_area a.subcategory_link").eq(0).parents("table").eq(0);
var subCats = $("#content_area a.subcategory_link").detach().wrap("<li>").parent();


if (subCats.length!=0){

	//var subCatList = $("<ul>").attr("id", "subcategory-link").append(subCats);
	//var sectionHeading = $("<div>").attr("class", "subcategory-heading").text("ALL " + sectionName.toUpperCase() + " WEAR" );

	//$("<div>").attr("class","left").prependTo($("#content_area"));
	//$("#content_area .left").prepend(subCatList).prepend(sectionHeading);
	$("<div>").attr("class","left").append(nav).prependTo($("#content_area"));
	
	
	$("#content_area b:contains('Choose a sub category:')").parents("table").remove();
	// remove category tables
	catsTable.remove();
	
	
	
	var catImage = $("#content_area img[src*='categories']");
	if (catImage.length==1){
		var catImageTables = $("#content_area img[src*='categories']").parents("table");
		
		var src = catImage.attr("src");
		//alert(src)
		catImage.detach();
		$("<div>").attr("id", "cat-image").appendTo("#content_area").append(catImage);
	
	
	
		//c.appendTo("#content_area");
		//catImage.attr("id", "cat-image").attr("border","");
	
		catImageTables.remove();
	}
	
}
// section name




/*
  ____                _            _     _     _     _   
 |  _ \ _ __ ___   __| |_   _  ___| |_  | |   (_)___| |_ 
 | |_) | '__/ _ \ / _` | | | |/ __| __| | |   | / __| __|
 |  __/| | | (_) | (_| | |_| | (__| |_  | |___| \__ \ |_ 
 |_|   |_|  \___/ \__,_|\__,_|\___|\__| |_____|_|___/\__|
*/

if ($(".search_results_section").length!=0){

	currentSubSubSection = breadcrumbContainer.find("a").eq(2).text();

	searchResults = $(".search_results_section").detach();
	searchResults.parents("table").remove();

	// remove subsection name if same as section
	var headingTxt = (currentSection.toLowerCase().replace(" ","")==currentSubSection.toLowerCase().replace(" ","")) ? currentSubSubSection : (currentSubSection + " " + currentSection + " " + currentSubSubSection);
	
	var heading = $("<div>").text(headingTxt).attr("class", "productListHeading");
	
	
	$("#content_area table").remove();
	
	
	$("<div>").attr("class","left").append(nav).prependTo($("#content_area"));
	$("<div>").attr("class","right3").append(heading).append(searchResults).appendTo($("#content_area"));
	$("#content_area").append("<br clear=\"all\"/>");
	// remove <br> in product
	$(".search_results_section .productnamecolor").parent().find("br").remove();
	
	$(".search_results_section td[background*='Grid_Divider_Horizontal.gif']").addClass("horizontalDivider");
	
	// shift up textbox in results_per_page
	$(".results_per_page_select").parents("tr").eq(0).find("input[type='text']").css({position:"relative",top:"-1px"});	
	
}


	
/*
  ____                _            _     ____       _         _ _     
 |  _ \ _ __ ___   __| |_   _  ___| |_  |  _ \  ___| |_  __ _(_) |___ 
 | |_) | '__/ _ \ / _` | | | |/ __| __| | | | |/ _ \ __|/ _` | | / __|
 |  __/| | | (_) | (_| | |_| | (__| |_  | |_| |  __/ |_| (_| | | \__ \
 |_|   |_|  \___/ \__,_|\__,_|\___|\__| |____/ \___|\__|\__,_|_|_|___/
 
*/

if (productName!=""){


	currentSubSubSection = breadcrumbContainer.find("a").eq(2).text();

	var heading = $("<div>").attr("class","productName").append(productName);
	// add product name
	productDetailsTable.find("b>font.colors_productprice").parents("table").eq(0).parent().prepend( heading );

	
	form = $("#content_area form[name='MainForm']");	
	

	form.prepend("<br clear=\"all\"/>");
	$("<div>").attr("class","right2").append(productDetailsTable).prependTo(form);

	$("<div>").attr("class","left").append(nav).prependTo(form);

	// move add to cart button into first cell
	btnaddtocart = $("input[name='btnaddtocart']");
	toEl = $("input[name^='QTY.']").parents("tr").eq(0).after("<tr><td id=\"addButton\">&nbsp;</td></tr>").parents("table").eq(0).find("#addButton");//.css({background:"yellow"});


	btnaddtocart.attr("class","basketButton").detach();
	toEl.append(btnaddtocart.attr("class","basketButton"));
	
	// move add to bag table for products without variant
	if ($("#options_table").length==0){
	
		var $t = $("input[name^='QTY.']").parents("table").eq(0);
		var $t2 = $t.parents("table").eq(0).find(".colors_productprice").parents("table").eq(0);
		$t2.after($t);
	
	}	
	
	
	// left align image  + buttons
	$("#product_photo").parents("td").eq(0).attr("align","left");
	
	$("#content_area").wrapInner("<div class=\"bg\">");

	// related products
	$(".colors_background_main").css("border","10px solid #fff");
	$(".colors_background_main td").attr("align","left");
	$(".PageText_L666n").css({position:"relative",left:"10px"});
	$("#Header_ProductDetail_ProductDetails").css("display","none");
	$(".colors_backgroundlight").css("width","950px");
	

	$(".PageText_L483n").css({color:"#ec008c"});	
	
}

/*
   ____            _   
  / ___| __ _ _ __| |_ 
 | |    / _` | '__| __|
 | |___| (_| | |  | |_ 
  \____|\__,_|_|   \__|
                       
*/
if (window.location.pathname.toLowerCase().indexOf("/shoppingcart.asp")==0){

	var span = $(".PageText_L258n");
	span.parent().text(span.text());

	$("input[name='email']").parents("td").eq(0).css("paddingBottom","6px");

	$(".colors_productprice").parents("table").eq(0).find("b").wrapInner("<font style='font-weight:bold!important;color:#ec008c;'>");	
	$(".colors_productprice").css({position:"relative",top:"9px"});
	$(".colors_productprice *").css("color","red!important");
	$("#btnRecalculate").css({position:"relative",left:"6px"});
	
	//make first table 100%
	$("#content_area table").eq(0).attr("width","100%");
	
	//add wrapper
	$("#content_area").wrapInner("<div class=\"bg\">");
}



/*
   ____ _               _                 _   
  / ___| |__   ___  ___| |__   ___  _   _| |_ 
 | |   | '_ \ / _ \/ __| '_ \ / _ \| | | | __|
 | |___| | | |  __/ (__| | | | (_) | |_| | |_ 
  \____|_| |_|\___|\___|_| |_|\___/ \__,_|\__|
*/

if ($("form[name='OnePageCheckoutForm']").length!=0){

	$("form[name='OnePageCheckoutForm']").css({display:"block",marginBottom:"15px"});

}

/*
  _                 _       
 | |     ___   __ _(_)_ __  
 | |    / _ \ / _` | | '_ \ 
 | |___| (_) | (_| | | | | |
 |_____|\___/ \__, |_|_| |_|
              |___/         

*/

if ($("form[name='loginform']")){

	$("form[name='loginform'] input[name='imageField2']").parents("tr").eq(0).attr("align","left").prepend("<td>&nbsp;</td>");
	$("form[name='loginform'] div[id^='div_articleid_']").css("marginTop","5px");
	$("form[name='loginform'] #div_articleid_94").css("marginBottom","7px");
	var span = $("form[name='loginform'] .PageText_L258n");
	span.parent().text(span.text());
}

/*
  _   _      _       
 | | | | ___| |_ __  
 | |_| |/ _ \ | '_ \ 
 |  _  |  __/ | |_) |
 |_| |_|\___|_| .__/ 
              |_|
*/

if (window.location.pathname=="/help.asp"){

	$("table[width='90%']").attr("width","100%");
	$(".colors_productname").css("color","#ec008c");
	$("#div_articleid_108").css({position:"relative",left:"-8px"});

}

/*
  __  __            _                               _   
 |  \/  |_   _     / \   ___  ___  ___  _   _ _ __ | |_ 
 | |\/| | | | |   / _ \ / __|/ __|/ _ \| | | | '_ \| __|
 | |  | | |_| |  / ___ \ (__| (__| (_) | |_| | | | | |_ 
 |_|  |_|\__, | /_/   \_\___|\___|\___/ \__,_|_| |_|\__|
         |___/ 
*/

if (window.location.pathname=="/myaccount.asp"){

	$(".colors_lines_light").attr("cellpadding","0");
	
	
	var span = $(".PageText_L375n"); 
	span.parent().wrap("div");
	span.parents("div").eq(0).css({width:"500px",display:"block",textAlign:"left"});
	span.parent().text(span.text());
}

/*
  ____  _                                                       _   _             
 / ___|| |__   _____      __  _ __   __ ___   __  ___  ___  ___| |_(_) ___  _ __  
 \___ \| '_ \ / _ \ \ /\ / / | '_ \ / _` \ \ / / / __|/ _ \/ __| __| |/ _ \| '_ \ 
  ___) | | | | (_) \ V  V /  | | | | (_| |\ V /  \__ \  __/ (__| |_| | (_) | | | |
 |____/|_| |_|\___/ \_/\_/   |_| |_|\__,_| \_/   |___/\___|\___|\__|_|\___/|_| |_|
                                                                                  
*/


// remove subsection name if same as section
if (currentSection.toLowerCase().replace(" ","")==currentSubSection.toLowerCase().replace(" ","")){
	$(".nav_selected").eq(0).remove();
}

$("#nav>ul>li[class!='"+currentSection+"']").css("display","none");

$("#nav .subnav a").prepend(" - ");


// add highlight to current sub cat
$("#nav .subnav").eq(0).parent().prev().find("a").addClass("on");

// add highlight to current sub sub cat



if (currentSubSubSection!="") $("#nav .subnav:contains('"+ currentSubSubSection +"')").find("a").addClass("on");

/*
  _   _ _       _     _ _       _     _     ____            _   _             
 | | | (_) __ _| |__ | (_) __ _| |__ | |_  / ___|  ___  ___| |_(_) ___  _ __  
 | |_| | |/ _` | '_ \| | |/ _` | '_ \| __| \___ \ / _ \/ __| __| |/ _ \| '_ \ 
 |  _  | | (_| | | | | | | (_| | | | | |_   ___) |  __/ (__| |_| | (_) | | | |
 |_| |_|_|\__, |_| |_|_|_|\__, |_| |_|\__| |____/ \___|\___|\__|_|\___/|_| |_|
          |___/           |___/                                               
*/

if (currentSection!="") $("#topnav ."+currentSection +" a"  ).addClass("on");

var pageId = getParameterByName("ID");
if (pageId && pageId=="240"){
	$("#topnav .vicky a"  ).addClass("on");
}


}catch(e){}

$("#content_area").css("visibility","visible");
$("#nav").css("display","block");


});

