/* ================================================================ 
This copyright notice must be kept untouched in the stylesheet at 
all times.

The original version of this script and the associated (x)html
is available at http://www.stunicholls.com/menu/pro_drop_1.html
Copyright (c) 2005-2007 Stu Nicholls. All rights reserved.
This script and the associated (x)html may be modified in any 
way to fit your requirements.
=================================================================== */
stuHover = function() {
if (document.getElementById("nav") != null){
	var cssRule;
	var newSelector;
	for (var i = 0; i < document.styleSheets.length; i++)
		for (var x = 0; x < document.styleSheets[i].rules.length ; x++)
			{
			cssRule = document.styleSheets[i].rules[x];
			if (cssRule.selectorText.indexOf("LI:hover") != -1)
			{
				 newSelector = cssRule.selectorText.replace(/LI:hover/gi, "LI.iehover");
				document.styleSheets[i].addRule(newSelector , cssRule.style.cssText);
			}
		}
	var getElm = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<getElm.length; i++) {
		getElm[i].onmouseover=function() {
			this.className+=" iehover";
		}
		getElm[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" iehover\\b"), "");
		}
	}
}
}

if (window.attachEvent) window.attachEvent("onload", stuHover);



function AllOff(k) {
		for (var i=1; i <= k; i++) {
			var oFeature = document.getElementById('IMG' + i);
			oFeature.style.opacity = "0";
			oFeature.style.filter = "alpha(opacity=0)";
		}
	}
function pAllOff(k) {
		for (var i=1; i <= k; i++) {
			var oFeature = document.getElementById('pIMG' + i);
			oFeature.style.opacity = "0";
			oFeature.style.filter = "alpha(opacity=0)";
		}
	}
function aAllOff(k,l) {
		for (var i=0; i <= k; i++) {
			var oFeature = document.getElementById(l +'IMG' + i);
			oFeature.style.opacity = "0";
			oFeature.style.filter = "alpha(opacity=0)";
		}
	}
function fade(eElement, nStart, nEnd, nDuration, fCallback) {

	this.nOffset = 8;
	this.nOpacity = nStart;
	this.nStart = nStart;
	this.nEnd = nEnd;
	this.nDuration = nDuration;
	this.fCallback = fCallback;
	this.e = eElement;
	this.nInterval = 0;
	this.bFading = false;
}

fade.prototype.fadeCycle = function() {

	if (this.nEnd < this.nStart) {	
		if (this.nOpacity > this.nEnd) {
			this.nOpacity -= this.nOffset;
		} else {
			this.finalize();
		}
	} else {
		if (this.nOpacity < this.nEnd) {
			this.nOpacity += this.nOffset;
		} else {
			this.finalize();
		}
	}
	
	this.setOpacity(this.nOpacity/100);

}

fade.prototype.setOpacity = function(nOp) {	
	this.e.style.opacity = nOp;
	this.e.style.filter = "alpha(opacity=" + (nOp*100) + ")";
}

fade.prototype.finalize = function() {
	this.nOpacity = this.nEnd;
	this.bFading = false;
	clearInterval(this.nInterval);	
	if (this.fCallback) { this.fCallback(); }
}

fade.prototype.isFading = function() {
	return (this.bFading == true) ? true : false;
}

fade.prototype.start = function() {
	var oSelf = this;
	this.bFading = true;
	this.nInterval = setInterval(function() { oSelf.fadeCycle(); }, (this.nDuration / this.nOffset));
}

fade.prototype.stop = function() {
	this.bFading = false;
	clearInterval(this.nInterval);
}
var nCurrent = 0;
var pCurrent = 0;
function flash(n,m)
{
	var obj = eval("document.getElementById('YarnColorDiv" + n + "')");
	for(i=1;i<=m;i++)
	{
		c = "document.getElementById('YarnColorDiv" + i + "')";
		
	    obj1 = eval(c);
	    if(obj1.id==obj.id)
	   {
		    obj1.style.display = "";
		}
		else
		{
		    obj1.style.display="none";
		}
     }
	
	var objIMG = eval("document.getElementById('IMG" + n + "')");
	objIMG.style.marginLeft = "0px";
	
	if( nCurrent != n)
	{
		nCurrent = n;
		AllOff(m);
		var f = new fade(objIMG, 0, 150, 150);
		f.start();
	}
}
function flash2(n,m)
{
	var obj = eval("document.getElementById('designimg" + n + "')");
	for(i=1;i<=m;i++)
	{
	    obj1 = eval("document.getElementById('designimg" + i + "')");
	    if(obj1.id==obj.id)
	   {
		    obj1.style.display = "";
		}
		else
		{
		    obj1.style.display="none";
		}
     }
	
	var objIMG = eval("document.getElementById('IMG" + n + "')");
	objIMG.style.marginLeft = "0px";
	
	if( nCurrent != n)
	{
		nCurrent = n;
		AllOff(m);
		var f = new fade(objIMG, 0, 150, 150);
		f.start();
	}
}

function flash3(n,m)
{
	var obj = eval("document.getElementById('proj" + n + "')");
	for(i=1;i<=m;i++)
	{
	    obj1 = eval("document.getElementById('proj" + i + "')");
	    if(obj1.id==obj.id)
	   {
		    obj1.style.display = "";
		}
		else
		{
		    obj1.style.display="none";
		}
     }
	
	var objIMG = eval("document.getElementById('pIMG" + n + "')");
	objIMG.style.marginLeft = "0px";
	
	if( pCurrent != n)
	{
		pCurrent = n;
		pAllOff(m);
		var f = new fade(objIMG, 0, 150, 150);
		f.start();
	}
};
var lCurrent = new Array();
var lCurrent2 = new Array();
lCurrent['a']=0;
lCurrent['b']=0;
lCurrent['c']=0;
lCurrent2['a']=0;
lCurrent2['b']=0;
lCurrent2['c']=0;
function flash_index(n,m,l)
{
	var obj = eval("document.getElementById('" + l + n + "')");
	for(i=0;i<=m;i++)
	{
	    obj1 = eval("document.getElementById('"+ l + i + "')");
	    if(obj1.id==obj.id)
	   {
		    obj1.style.display = "";
		}
		else
		{
		    obj1.style.display="none";
		}
     }
	var x ="document.getElementById('" + l + "IMG" + n + "')";
	var objIMG = eval(x);
	objIMG.style.marginLeft = "0px";
	
	if( lCurrent[l] != n)
	{
		var c =eval("document.getElementById('" + l + "IMG" + lCurrent[l] + "')");
		lCurrent[l] = n;
		aAllOff(m,l);
		var f = new fade(objIMG, 0, 150, 500);
		f.start();
	}
}


function nexta(l,m) {
	img_location = l;
	max_img = m;
	var c =eval("document.getElementById('" + l + "IMG" + lCurrent2[l] + "')");
	var f = new fade(c, 150, 0, 500,function(){									 
		if(lCurrent2[img_location]==max_img){
		flash_index(0,max_img,img_location);
		lCurrent2[img_location]=0;
	} else {
		flash_index(++lCurrent2[img_location],max_img,img_location);
	}
	
	});
	f.start();

};
function nextb(l,m) {
	img_location2 = l;
	max_img2 = m;
	var c =eval("document.getElementById('" + l + "IMG" + lCurrent2[l] + "')");
	var f = new fade(c, 150, 0, 500,function(){									 
		if(lCurrent2[img_location2]==max_img2){
		flash_index(0,max_img2,img_location2);
		lCurrent2[img_location2]=0;
	} else {
		flash_index(++lCurrent2[img_location2],max_img2,img_location2);
	}
	
	});
	f.start();

};

var img_location;
var max_img;

var q = new Array();
q['a']=0;
q['b']=0;
q['c']=0;
function slideshow(l,m) {
	if(l=='a'){
		nexta(l,m);
		q[l]=setTimeout("slideshow('"+l+"','"+m+"')",6000);
	} else {
		nextb(l,m);
		q[l]=setTimeout("slideshow('"+l+"','"+m+"')",7000);
	}
	
}


var lastBorder;
var curcloseout = 0;
function changeKitColor(x, c) {
	curcloseout = c;
	if(lastBorder!=null) {
		document.getElementById('c'+lastBorder).style.backgroundColor="#333";
		document.getElementById('c'+lastBorder).style.color="#eee";
	}
	lastBorder=x;
	document.getElementById('c'+x).style.backgroundColor="#fff";
	document.getElementById('c'+x).style.color="#000";
	document.f2.submit.value='Color '+x+' - Add to Cart >';
	document.f2.yColor.value=x;
}
function changeColor(x,p,o,undyed) {
	if(lastBorder!=null) {
		document.getElementById('c'+lastBorder).style.backgroundColor="#333";
		document.getElementById('c'+lastBorder).style.color="#eee";
	}
	lastBorder=x;
	curcloseout=p;
	// Closeout price
	p = o-(o*(p/100)); 
	document.getElementById('c'+x).style.backgroundColor="#fff";
	document.getElementById('xprice').innerHTML = p.toFixed(2);
	document.getElementById('c'+x).style.color="#000";
	calcprice(o,undyed);
	document.f2.submit.value+=' - Color '+x;
	document.f2.yColor.value=x;
}

/*
var packages=new Array()
packages['x100']='Cone 100g: '
packages['x150']='Cone 150g: '
packages['x200']='Cone 200g: '
packages['x250']='Cone 250g: '
packages['xskein']='Undyed Skeins: '
packages['xsample']='Samples: ' */

function changePackage(name,value) {
//	price = price.toFixed(2);
	//document.getElementById('xPackage').innerHTML=name + ' ' + yards + ' yards $' + price;
	//document.f2.yPackage.value=name;
	if(value!=''&&value!='0') {
		document.getElementById(name).innerHTML=packages[name] + value;
	} else {
		document.getElementById(name).innerHTML='';
	}
}

function changePattern(x,name) {
	document.getElementById('xPattern').innerHTML=name;
	document.f2.yPattern.value=x;
}

function checkform() {

		if(document.f2.c250.value>0&&document.f2.yColor.value=='') {
					alert('Please pick a color');
					return false;
		}

	/* if(document.f2.yPackage.value=='') {
		alert('Please pick a package');
		return false;
	} */
	return true;
	
}

function pcheckform() {
	if(document.f2.yColor.value=='') {
		alert('Please pick a color');
		return false;
	}	
	if(document.f2.Qty.value<1) {
		alert('Please enter a quantity');
		return false;
	}
	return true;
	
}


function showdetail(id) {
	idname ='yarndetail' + id;
	document.getElementById('yarnviewleft').innerHTML=document.getElementById(idname).innerHTML;
}

function changepic(url, des, num, tmax) {
	for(i=1;i<=tmax;i++) {
		document.getElementById('i'+i).className="not";
	}
	document.getElementById('i'+num).className="selected";
	document.getElementById('mainimg').src=url;
	document.getElementById('maintxt').innerHTML=des;
}

function changePrice(price,i){
	var x = price[i]*((100-curcloseout)/100);
	document.getElementById('pcost').innerHTML=x.toFixed(0);
}

var pcount=1;
function nextp(c) {
	if(pcount==c){
		flash3(1,c);
		pcount=1;
	} else {
		flash3(pcount+1,c);
		pcount++;
	}

}
function prevp(c) {
	if(pcount==1){
		flash3(c,c);
		pcount=c;
	} else {
		flash3(pcount-1,c);
		pcount--;
	}

}

function showcenter(f) {
	document.getElementById("menuyarn").innerHTML = document.getElementById(f).innerHTML;
	
}

function setstitches(){
	var vals = document.form3.yarn.value;
	vals = vals.split('|');
	document.getElementById("stitch4").innerHTML = vals[0];
	document.getElementById("rows4").innerHTML = vals[1];
	document.getElementById("needle").innerHTML = vals[2];	
}
