// stoo slideShow 1.1
// (c)2007 Stoo - http://www.glitch.co.nz
//
// Credit where credit is due: Inspiration from JonDesign's SmoothGallery (http://www.jondesign.net/)
// and of course Valerio's mootools (http://mootools.net/)
// --------------------------------------------------------------------------------------------------------------

// ---------------------------------------------------
// variables

// ---------------------------------------------------
// nav menu
function startList() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("nav");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
}

function sfHover() {
	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);

// ---------------------------------------------------
// bac image
function startGallery() {
	var myGallery = new gallery($('myGallery'), {
	timed: true,
	showArrows: false,
	showCarousel: false,
	embedLinks: false,
	showInfopane: false
});
}


// ---------------------------------------------------
// popup
function popup(url,target,w,h) {
	window.open(url,target,'menubar=no,toolbar=no,location=no,status=no,scrollbars=yes,resizable=yes,dependent=yes,width='+w+',height='+h);
	return false;
}


// ---------------------------------------------------
// dropdown menus
function checkForm( id ) {
	
	var newcolor = $('color['+id+']').value;
	var newsize = $('size['+id+']').value;
	var newqty = $('qty['+id+']').value;
	
	if (newcolor && newsize && newqty)
	{	
		return true;
	} else {
		alert('Please fill in three fields: colour, size and quantity');
		return false;
	}

}

function changeChoice( id ) {
	
	var newcolor = $('color['+id+']').value;
	var newsize = $('size['+id+']').value;
	var newqty = $('qty['+id+']').value;
	
	if (newcolor && newsize && newqty) {
		
		var url = "checkstock.php";
 
		/**
	 	* The simple way for an Ajax request, use onRequest/onComplete/onFailure
	 	* to do add your own Ajax depended code.
		 */
		new Ajax(url, {
			method: 'get',
			data: 'id='+id+'&color='+newcolor+'&size='+newsize+'&qty='+newqty,
			onComplete: showResponse
			//update: $('stockmsg['+id+']')
		}).request();
		
	}

}

function showResponse( request ) {		
		
		var rs = Json.evaluate(request);
		
		if ( parseInt(rs['instock']) < parseInt(rs['qty']) ){
			//alert ('still some left');
			$('stockmsg['+rs['id']+']').setHTML(rs['msg1']+'<br />'+rs['msg2']);
			$('submit['+rs['id']+']').disabled = true;
		} else {
			$('stockmsg['+rs['id']+']').setHTML('');
			$('submit['+rs['id']+']').disabled = false;
		}
}

function changeSize( print ) {
	
	var newcolor = $('color['+print+']').value;
	var newsize = $('size['+print+']').value;
	var newqty = $('qty['+print+']').value;
	
	if (newcolor && newsize && newqty) {
		
		if ( stockArr[print][newcolor][newsize] < newqty ){
			//alert ('still some left');
			//alert ('qty:'+stockArr[print][newcolor][newsize]);
			$('stock['+print+']').setText('sold out');
			$('submit').disabled = true;
		} else {
			$('stock['+print+']').setText('');
			$('submit').disabled = false;
		}
	}
}

function changeQty( print ) {
	//$('stocker['+print+']').setText('some text');
	
	var newcolor = $('color['+print+']').value;
	var newsize = $('size['+print+']').value;
	var newqty = $('qty['+print+']').value;
	
	if (newcolor && newsize && newqty) {
		
		//var submitObj = $('submit');
		
		
		if ( stockArr[print][newcolor][newsize] < newqty ){
		//if ( newqty > 3 ){
			//alert ('still some left');
			//alert ('qty:'+stockArr[print][newcolor][newsize]);
			//var txt = $('stocker['+print+']').getText();
			//alert ( txt );
			$('stock['+print+']').setText('sold out');
			$('submit').disabled = true;
			//$('stocker['+print+']').display = 'table-row';
		} else {
			$('stock['+print+']').setText('');
			$('submit').disabled = false;
		}
			
			//var mySlide = new Fx.Slide('stock'+print);
			
			
			//mySlide.slideIn();
	}
}


/*function changeDiv(the_div,the_change)
{
  var the_style = getStyleObject(the_div);
  if (the_style != false)
  {
    the_style.display = the_change;
  }
}*/



// ---------------------------------------------------
// init
function run() {
	//Window.disableImageCache(); // Trying to disable the imageCache to fix IE6 issues
	
	emailCloak();
	startList();
	//sfHover();
	
	//startGallery();
	domRollover();
	//new Png();
}

Window.onDomReady(run);

// --------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------
