// Preload

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

// these global variables all line up with variable i
// first one are the section names
// second is for the number of images
// third is the extension of the big images

var arNav = new Array('headers','about','news','press','stockists','stores','seams','prints','bags','sweats','pockets','colors','underwears','shirts','mens','whiteshirts','newbags','evenings','standards','knits','shoes','sunglassess','jewelrys','weddingdresss');

function WM_imageSwap(daImage, daSrc){
  var objStr,obj;

  /*
    WM_imageSwap()
    Changes the source of an image.

    Source: Webmonkey Code Library
    (http://www.hotwired.com/webmonkey/javascript/code_library/)

    Author: Shvatz
    Author Email: shvatz@wired.com

    Usage: WM_imageSwap(originalImage, 'newSourceUrl');

    Requires: WM_preloadImages() (optional, but recommended)
    Thanks to Ken Sundermeyer (ksundermeyer@macromedia.com) for his help
    with variables in ie3 for the mac. 
    */

  // Check to make sure that images are supported in the DOM.
  if(document.images){
    // Check to see whether you are using a name, number, or object
    if (typeof(daImage) == 'string') {
      // This whole objStr nonesense is here solely to gain compatability
      // with ie3 for the mac.
      objStr = 'document.' + daImage;
      obj = eval(objStr);
      obj.src = daSrc;
    } else if ((typeof(daImage) == 'object') && daImage && daImage.src) {
      daImage.src = daSrc;
    }
  }
}


// functions navOn & navOff

/* in order for this and navOff to work, i in the html document MUST line up 
with i in the blocking function AND the ID number 
in the hidden DIV - always check that these numbers are the same throughout the section! */


function navOn(i)
{

  var objStr,obj;

  // Check to make sure that images are supported in the DOM.
  if(document.images){
    // Check to see whether you are using a name, number, or object
    if (typeof(arNav[i]) == 'string') {
      // This whole objStr nonesense is here solely to gain compatability
      // with ie3 for the mac.
      objStr = 'document.' + arNav[i];
      obj = eval(objStr);
      obj.src = 'images/' + arNav[i] + '_on.gif';
    } else if ((typeof(arNav) == 'object') && arNav[i]) {
      daImage.src = 'images/' + arNav[i] + '_on.gif';
    }
  }
  	
}




function navOff(i){
  var objStr,obj;

var state = document.getElementById('nr'+i).style.display;
var down = 'block';

if (state != down)
{


  // Check to make sure that images are supported in the DOM.
  if(document.images){
    // Check to see whether you are using a name, number, or object
    if (typeof(arNav[i]) == 'string') {
      // This whole objStr nonesense is here solely to gain compatability
      // with ie3 for the mac.
      objStr = 'document.' + arNav[i];
      obj = eval(objStr);
      obj.src = 'images/' + arNav[i] + '_off.gif';
    } else if ((typeof(arNav) == 'object') && arNav[i]) {
      daImage.src = 'images/' + arNav[i] + '_off.gif';
    }
  }
}
}




// resizeImg()
function resizeImg(imgId,width,height)
{
var objStr,obj;
if(document.images) 
	{
	objStr = 'document.' + imgId;
	obj = eval(objStr);
	obj.width = width;
	obj.height = height;
	}
}





// blocking()
// Source: www.xs4all.nl/~ppk
var supported = (document.getElementById || document.all);

if (supported)
{
	document.write("<style type='text/css'>");
	document.write(".dropdown { display:none; }");
	document.write("</style>");

	var max = 12;
	var shown = new Array();
	for (var i=1;i<=max;i++)
	{
		shown[i+1] = false;
	}

}

function blocking(i)
{
	if (!supported)
	{
		alert('This link does not work in your browser.');
		return;
	}
	shown[i] = (shown[i]) ? false : true;

	current = (shown[i]) ? 'block' : 'none';

	if (document.getElementById)
	{
		document.getElementById('nr'+i).style.display = current;
	}
	else if (document.all)
	{
		document.all['number'+i].style.display = current;	
	}

}

// ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// 
// Coded by Travis Beckham
// http://www.squidfingers.com | http://www.podlob.com
// If want to use this code, feel free to do so, but please leave this message intact.
//
// ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// --- version date: 06/13/04 ---------------------------------------------------------

tooltip = {
	name : "tooltipDiv",
	offsetX : 10,
	offsetY : 10,
	tip : null
};
tooltip.init = function () {
	if (!document.getElementById) return;
	
	// It would be nice to be able to generate the tooltip div, 
	// but when using document.createElement Explorer5/MacOS9, 
	// the tooltip div becomes 100% of the window height.
	// Therefore, we have to use document.getElementById to access
	// a div that is already in the body.
	
	// this.tip = document.createElement ("div");
	// this.tip.setAttribute ("id", this.name);
	// document.body.appendChild (this.tip);
	
	this.tip = document.getElementById (this.name);
	if (this.tip) document.onmousemove = function (evt) {tooltip.move (evt)};
};
tooltip.move = function (evt) {
	var x=0, y=0;
	if (document.all) {// Explorer
	
		// Explorer5 contains the documentElement object but it's empty, 
		// so we must check if the scrollLeft property is available.
		
		// If Explorer6 is in Quirks mode, the documentElement properties 
		// will still be defined, but they will contain the number 0.
		
		// If Explorer6 is in Standards compliant mode, the document.body 
		// properties will still be defined, but they will contain the number 0.
		
		x = (document.documentElement && document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft;
		y = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
		x += window.event.clientX;
		y += window.event.clientY;
		
	} else {// Mozilla
		x = evt.pageX;
		y = evt.pageY;
	}
	// If the style property value is not a string containing the unit measurement,
	// browsers in standard compliant mode will not set the property.
	this.tip.style.left = (x + this.offsetX) + "px";
	this.tip.style.top = (y + this.offsetY) + "px";
};
tooltip.show = function (text) {
	if (!this.tip) return;
	this.tip.innerHTML = text;
	// Without the next line, Explorer5/Mac has a redraw problem.
	this.tip.style.visibility = "visible";
	this.tip.style.display = "block";
};
tooltip.hide = function () {
	if (!this.tip) return;
	// Without the next line, Explorer5/Mac has a redraw problem.
	this.tip.style.visibility = "hidden";
	this.tip.style.display = "none";
	this.tip.innerHTML = "";
};



//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
// FORM TO PP

var itemNum = 0;

function addItem ( id, name, amount ){
	var storeForm 	= document.getElementById('storeForm');
	var quantity 	= document.getElementById('quantity_'+id).value;
	if(quantity != 0 && !isNaN(quantity)){
		if(!document.getElementById('form_item_name_'+id)){
			
			document.getElementById('buy_'+id).style.display = "none";
			document.getElementById('cart_'+id).style.display = "inline";
			
			itemNum++;
			
			// NAME
			var newItem1 	= document.createElement('input');
			newItem1.setAttribute('id','form_item_name_'+id);
			newItem1.setAttribute('type','hidden');
			newItem1.setAttribute('name','item_name_'+itemNum);
			newItem1.setAttribute('value',name);
			storeForm.appendChild(newItem1);
			
			// AMOUNT
			var newItem2 	= document.createElement('input');
			newItem2.setAttribute('id','form_amount_'+id);
			newItem2.setAttribute('type','hidden');
			newItem2.setAttribute('name','amount_'+itemNum);
			newItem2.setAttribute('value',amount);
			storeForm.appendChild(newItem2);
			
			// QUANTITY
			var newItem3 	= document.createElement('input');
			newItem3.setAttribute('id','form_quantity_'+id);
			newItem3.setAttribute('type','hidden');
			newItem3.setAttribute('name','quantity_'+itemNum);
			newItem3.setAttribute('value',quantity);
			storeForm.appendChild(newItem3);
			
			// TOTAL
			var newItem4 	= document.createElement('input');
			newItem4.setAttribute('id','sas_total_'+id);
			newItem4.setAttribute('type','hidden');
			newItem4.setAttribute('value',(quantity*amount));
			storeForm.appendChild(newItem4);
			
			
			var buyTD	 	= document.getElementById('buy_'+id);
			buyTD.innerHTML = quantity+" in cart.";
		} else {
			document.getElementById('form_quantity_'+id).value = document.getElementById('quantity_'+id).value;
			document.getElementById('sas_total_'+id).value = parseInt(document.getElementById('quantity_'+id).value) * amount;
			document.getElementById('update_'+id).style.display = "none";
			document.getElementById('cart_'+id).style.display = "inline";
		}
	} else {
		document.getElementById('quantity_'+id).value = "1";
	}
	
}

function updateItem ( id ){
	if(document.getElementById('buy_'+id).style.display == "none"){
		document.getElementById('update_'+id).style.display = "inline";
		document.getElementById('cart_'+id).style.display = "none";
	}
}

function checkItem ( id ){
	if(document.getElementById('buy_'+id).style.display == "none"){
		if(document.getElementById('form_quantity_'+id).value == document.getElementById('quantity_'+id).value){
			document.getElementById('update_'+id).style.display = "none";
			document.getElementById('cart_'+id).style.display = "inline";
		}
	}
}

function deleteItem ( id ){
	tempElement = document.getElementById('form_item_name_'+id);
	tempElement.parentNode.removeChild(tempElement);
	
	tempElement = document.getElementById('form_amount_'+id);
	tempElement.parentNode.removeChild(tempElement);
	
	tempElement = document.getElementById('form_quantity_'+id);
	tempElement.parentNode.removeChild(tempElement);
	
	tempElement = document.getElementById('sas_total_'+id);
	tempElement.parentNode.removeChild(tempElement);
	
	var buyTD = document.getElementById('buy_'+id);
	buyTD.innerHTML = "&nbsp;BUY&nbsp;";
	
	document.getElementById('quantity_'+id).value = "1";

	document.getElementById('buy_'+id).style.display = "inline";
	document.getElementById('cart_'+id).style.display = "none";
}

function pppost ( selectedtype ){
	
	// GET TOTAL IN CART
	var tempTotal = 0;
	var elem = document.getElementById('storeForm').elements;
	for(var i = 0; i < elem.length; i++){
		if(elem[i].id.substr(0,10) == "sas_total_"){
			tempTotal += parseInt(elem[i].value);
		}
	}
	document.getElementById('totalCost').value  = tempTotal;
	
	if(tempTotal <= 200){
		document.getElementById('formShipping').value = parseInt(document.getElementById('shipping').options[document.getElementById('shipping').selectedIndex].value);
	} else if(tempTotal <= 500) {
		document.getElementById('formShipping').value = parseInt(document.getElementById('shipping').options[document.getElementById('shipping').selectedIndex].value) + parseInt(5);
		//alert(document.getElementById('formShipping').value);
	} else {
		document.getElementById('formShipping').value = 0;
	}
	
	//////////////////////////////////////////////////////////////////////////////////
	// Fix for sequential PayPal names - March 22nd 2010
	j=1;
	for(var i = 0; i < elem.length; i++){
		if(elem[i].id.substr(0,15) == "form_item_name_"){
			this_id = elem[i].id.substr(15);
			elem[i].name = 'item_name_'+j;
			document.getElementById('form_amount_'+this_id).name = 'amount_'+j;
			document.getElementById('form_quantity_'+this_id).name = 'quantity_'+j;
			j++;
		}
	}
	//////////////////////////////////////////////////////////////////////////////////
	
	document.storeForm.submit();
}

function changeShipping ( tempValue ){
	document.getElementById('formShipping').value = tempValue;
	if(tempValue == '0.00'){
		// INTERNATIONAL WARNING
		alert('You must call in this order to get overnight shipping...');
	}
}

//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////
