default_bg = '8';

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

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

document.addEvent('domready', function(){
	var currentbg = readCookie('currentbg');
	var bgpath = "images/backgrounds/";
	if (currentbg != null)
	{
		//alert(currentbg);
		changeBGto(currentbg);
	}
	else
	{
		//alert(currentbg+" 2");
		changeBGto(default_bg);
	}

});

function changeBGto(bg)
{
	//0="flamingo"=facfd8, 1="black"=231f20, 2="popsicle"=da527a, 3="citron"=fff216, 4="baltic"=006ab6, 5="aqua"=00a9c4, 6="white"=white, 7="dot"=bg_dot.gif, 8="stripe"=bg_stripe.gif, 9="gingham"=bg_gingham.gif, 10="nature"=bg_nature.gif, 11="plaid"=bg_plaid.gif
	switch(bg)
	{
		case '0': document.body.style.backgroundImage = "none";
				document.body.style.backgroundColor = "#d00ffe";
				break;
		case '1': document.body.style.backgroundImage = "none";
				document.body.style.backgroundColor = "#000000";
				break;
		case '2': document.body.style.backgroundImage = "none";
				document.body.style.backgroundColor = "#a3c76f";
				break;
		case '3': document.body.style.backgroundImage = "none";
				document.body.style.backgroundColor = "#b90012";
				break;
		case '4': document.body.style.backgroundImage = "none";
				document.body.style.backgroundColor = "#1e0080";
				break;
		case '5': document.body.style.backgroundImage = "none";
				document.body.style.backgroundColor = "#f1ffa7";
				break;
		case '6': document.body.style.backgroundImage = "url(/images/backgrounds/Boxplaid.jpg)";
				document.body.style.backgroundColor = "white";
				break;
		case '7': document.body.style.backgroundImage = "url(/images/backgrounds/DigiBlack.jpg)";
				document.body.style.backgroundColor = "white";
				break;
		case '8': document.body.style.backgroundImage = "url(/images/backgrounds/Gingham.jpg)";
				document.body.style.backgroundColor = "white";
				break;
		case '9': document.body.style.backgroundImage = "url(/images/backgrounds/lightstripe.jpg)";
				document.body.style.backgroundColor = "white";
				break;
		case '10': document.body.style.backgroundImage = "url(/images/backgrounds/pindot.gif)";
				document.body.style.backgroundColor = "white";
				break;
		case '11': document.body.style.backgroundImage = "url(/images/backgrounds/stripe.gif)";
				document.body.style.backgroundColor = "white";
				break;
		default: break;
	}
	//alert("img="+document.body.style.backgroundImage+" color="+document.body.style.backgroundColor+" bg="+bg);
}

function revertBG()
{
	var currentbg = readCookie('currentbg');
	if (currentbg != null)
	{
		//alert(currentbg);
		changeBGto(currentbg);
	}
	else
	{
		//alert(currentbg+" 2");
		changeBGto(default_bg);
	}	
}

function showBG()
{
	document.getElementById('change_bg').style.display = "block";
}

function hideBG()
{
	document.getElementById('change_bg').style.display = "none";
}

function changebg(bg)
{
	createCookie('currentbg', bg, 7);
	changeBGto(bg);
}

if(document.images)
{
  var image_array = new Array();
	
  // path to the directory with images
  var path = '/images/nav/';

  image_array[0] = path + "accessories_over.gif";
  image_array[1] = path + "blog_over.gif";
  image_array[2] = path + "clothing_over.gif";
  image_array[3] = path + "community_over.gif";
  image_array[4] = path + "lookbook_over.gif";
  image_array[5] = path + "ripzone_over.gif";
  image_array[6] = path + "snow_over.gif";
  image_array[7] = path + "team_over.gif";
  
  path = '/images/nav/clothing/';
  image_array[8] = path + "boardshorts_over.png";
  image_array[9] = path + "bottoms_over.png";
  image_array[10] = path + "chickletts_over.png";
  image_array[11] = path + "dresses_over.png";
  image_array[12] = path + "fleece_over.png";
  image_array[13] = path + "graphic_tees_over.png";
  image_array[14] = path + "lil_chicks_over.png";
  image_array[15] = path + "shorts_over.png";
  image_array[16] = path + "swim_coverups_over.png";
  image_array[17] = path + "tanks_camis_over.png";
  image_array[18] = path + "tops_over.png";
  
  path = '/images/';
  image_array[19] = path + "marketing1_over.gif";
  image_array[20] = path + "marketing2_over.gif";
  image_array[21] = path + "spring_ad_over.gif";

  var preload_image = new Array ();
 
  for(var i=0; i<image_array.length; i++)
  {
    preload_image[i]= new Image();
    preload_image[i].src = image_array[i];
  }
}

sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

function rollover_sub(name)
{
  var fullpath = '/images/nav/clothing/' + name + '_over.png';
  document.images[name].src = fullpath;
}

function rollout_sub(name)
{
  var fullpath = '/images/nav/clothing/' + name + '.png';
  document.images[name].src = fullpath;
}

function popout(newURL) 
{
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(newURL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=248,height=48');");
	//window.open(newURL, '_blank', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=248,height=48');
}


var displayCS = 0;

function showElem(elem)
{
	document.getElementById(elem).style.display = "block";
}

function hideElem(elem)
{
	document.getElementById(elem).style.display = "none";
}

function showHideSearch(elem)
{
	newDisplay = (document.getElementById(elem).style.display == "none") ? "inline" : "none";
	document.getElementById(elem).style.display = newDisplay;
}

function clickCS()
{
	if (displayCS == 0)
	{
		showElem("customer_service");
		displayCS = 1;
	}
	else
	{
		hideElem("customer_service");
		displayCS = 0;
	}
}

function outCS()
{
	if (displayCS == 0)
	{
		hideElem("customer_service");
	}
}
