var completeSetUp = false;

$(document).ready( function(){
	setUp(true);
});

function setUp(showflag) {
	if (!completeSetUp) {
		$('input.creative_searchBox').val('Search').focus(function(){
			if ($(this).val()=="Search") $(this).val("");
		}).blur(function(){
			if ($(this).val()=="") $(this).val("Search");
		});
		removeCellStyles();
		//formatTopNavLinks();
		removeSpacings();
	    //setLogo();
		//setTopNav();
		if (showflag) $('body').show();
		completeSetUp = true;		
	} 
}

function setLogo() {
	$('table.logo td:first').html($('#creative-logo').html()).attr('id','logo-cell');
	$('#creative-logo').hide();	
	$("#center-links").insertAfter('#logo-cell');
}

function setTopNav() {
	$('#logo-cell').parent().parent().append('<tr id="nav-row"></tr>');
	$('#nav-row').append($('#top-nav'));
}

function removeSpacings() {
	$("img[src$='/themes/iwsclassic/variations/blue/images/1.gif']").parent("td[width='10']").remove();
	$("img[src$='/themes/iwsclassic/variations/blue/images/1.gif']").remove();
	$('.g').remove();	
}

function formatTopNavLinks(){
	//remove pipes
	if ($('#myaccountnav').length > 0) $('#myaccountnav').html($('#myaccountnav').html().replace(/\|/g,""));
	//remove home
	$('#myaccountnav').children('a:contains("Home")').remove();
	//format cart
	viewcart = $('#myaccountnav').children('a:contains("View Cart")').html('Cart <img class="png_bg" src="/images/icon_cart.png" />').attr('id','cart').appendTo('#myaccountnav');	
	
}

function removeCellStyles(){
	$('table,tr,td').removeAttr('cellSpacing').removeAttr('cellPadding').removeAttr('border').removeAttr('valign').removeAttr('align').removeAttr('width').removeAttr("bgcolor");
	$('table.content').children('tbody').children('tr').children('td').css('vertical-align','top').children('table').css('width',"100%");
}

function reformatBreadcrumbs() {
	$('#breadcrumbs').remove();
	$('.crumbHome').parent().attr('id','breadcrumbs');
	original_breadcrumbs = $('#breadcrumbs').clone();
	$('#breadcrumbs').empty();
	original_breadcrumbs.children('span').each( function() {
		//strip out ids and classes and re-id and class
		$(this).attr('class','breadcrumb').attr('id','');
		//remove h2 and arrows
		$(this).html($(this).find('a,b,h2'));
		$(this).addClass('crumb');
		$(this).appendTo('#breadcrumbs');
	});
	$('#breadcrumbs span:first').removeClass('crumb').addClass('first');
	$('#breadcrumbs span:last').removeClass('crumb').addClass('last');
	
	$('#breadcrumbs span.last').before('<span class="breadcrumb-divider-last"></span>');
	$('#breadcrumbs span.crumb').before('<span class="breadcrumb-divider"></span>');
	
}

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 results[1];
}

function newWindow( url, width, height, resize ) 
{ 
    var x = (screen.width-width)/2; 
    var y = (screen.height-height)/2 - 70; 
    var win = window.open(url,'newwindow','top=' + y + ',left=' + x + ',status=yes,toolbar=no,location=no,scrollbars=no,width='+width+',height='+height) 
    win.focus();
}

