//*********************    Place footer at the bottom of page *********************
function SI_body() {
	var d = document;
	
	if (d.body && d.body.style) {
		d.body.style.height = "26px";
		d.body.style.height = "auto";
		}
	}

function SI_positionFooter() {
	var d = document,w=window,dE=d.documentElement,dB=d.body;;
	if (!d.getElementById || !d.body.offsetHeight) return;
	
	// Reset our footer's margin-top...
	var footer = d.getElementById('footer');
	var mt = (footer.style.marginTop)?parseInt(footer.style.marginTop):0;
	
	var windowH	= (typeof(w.innerHeight)=='number')?w.innerHeight:(dE&&dE.clientHeight)?dE.clientHeight:(dB&&dB.clientHeight)?dB.clientHeight:0;
	var contentH	= d.getElementById('container').offsetHeight - mt;
	
	var footerMT	= (contentH <= windowH)?windowH-contentH:0;
	if (footerMT>0) {
		d.getElementById('footer').style.marginTop = footerMT + 'px';
		}
	}
	
function SI_init() {
	SI_positionFooter();
	SI_body();
	
	
	}
window.onload = SI_init;
window.onresize = SI_positionFooter;
//*********************//    Place footer at the bottom of page END // *********************

function CMASelectCategory(elm) {
    window.location = elm.value;
}


//************************** FAQ expand / collapse  ************************************

	var _h  = {};
// constructor
_h.Tree = function(id) { 
		
//img/htree_item.gif
		this.id = id;
		this.cookiePath = "/";
		this.useIcons   = true;
		this.useCookies = false;
		this.foldersAsLinks = false;
		this.oneSibling = true;
		this.icon = {
			align    :  "left",
			open		:	"images/arrow_open.gif",
			closed	    :	"images/arrow_closed.gif",
			item		:	"images/blank.gif"
		};
		this.navigation = this._keyNavigation;
};
_h.Tree.prototype.isSupported = (document.createElement &&
											document.getElementById && 
											document.getElementsByTagName);
_h.Tree.prototype.build = function() {
	if (!this.isSupported) return;
	this._list = document.getElementById(this.id);
	if (!this._list) return;
	this._list.className = "hTreeJS";
	var aLI = this._list.getElementsByTagName("li");
	for (var i=0;i<aLI.length;i++) {
		var oLI			= aLI[i];
		var aUL = oLI.getElementsByTagName("ul");
		if (aUL.length>0) {
			var oUL = aUL[0];
			oLI._hTree_folder = true;
			oUL.setAttribute('id',this.id+'-'+i);
			this.CreateTreeFolder(oLI,oUL);
		} else {
			oLI._hTree_folder = false;
			this.CreateTreeItem(oLI);
		}
	}
};
_h.Tree.prototype.CreateTreeFolder = function( oLI, oUL ) {
		var me = this;

		if (this.useCookies) { oLI._hTree_open = ((_h.getCookie(oUL.id)) == '1')?true:false; }
		oLI._hTree_open = (_h.hasClass(oUL, "open"))?true:oLI._hTree_open;
		oLI._hTree_open = (_h.hasClass(oUL, "closed"))?false:oLI._hTree_open;
		
/* Link */
		var aLinks = oLI.getElementsByTagName("a");
		if (!aLinks) this.CreateTreeItem(oLI); 
		
		var oLink = aLinks[0];
		if (oLink.parentNode != oLI) this.CreateTreeItem(oLI); 
		
		if (this.foldersAsLinks == false) { 
			oLink.href = "#";
			oLink.onclick = function() {
				me.toggle(oLI);
				return false;
			}
		}
		oLink.onkeydown = function(e) {
			var code;
			if (!e) var e = window.event;
			if (e.keyCode) code = e.keyCode;
			else if (e.which) code = e.which;
			me.navigation(code, oLI);
		}
		
		oLink._hTree_oLI = oLI;


/* IMG */		
		var oIMG = null;
		if (this.useIcons) {
			oIMG = document.createElement("img");

			oIMG.src = oLI._hTree_open ? this.icon.open : this.icon.closed;
			oIMG.alt = oLI._hTree_open ? "-": "+";
			oIMG.onclick = function() {
				me.toggle(oLI);
				return false;
			}
			oIMG._hTree_oLI = oLI;

			if (this.icon.align == "left") {
				oLI.insertBefore(oIMG,oLink);
			} else {
				oLI.insertBefore(oIMG,oLink.nextSibling);
			}
		}
		
		oLI._hTree_oUL		= oUL;
		oLI._hTree_oIMG	= oIMG;
		oLI._hTree_oLink  = oLink;

		oUL._hTree_oLI		= oLI;
		oUL.style.display = oLI._hTree_open?'block':'none'; 
	};
			
_h.Tree.prototype.CreateTreeItem = function(oLI) {
		var me = this;
		
		var aLinks = oLI.getElementsByTagName("a");
		if (aLinks) {
			var oLink = aLinks[0];
			if (oLink) {
				if (oLink.parentNode == oLI) {
					oLink.onkeydown = function(e) {
						var code;
						if (!e) var e = window.event;
						if (e.keyCode) code = e.keyCode;
						else if (e.which) code = e.which;
						me.navigation(code, oLI);
					}
				}
				oLI._hTree_oLink  = oLink;
			}		
		}

		oLI._hTree_open = false;

		if (this.useIcons) {
			var oIMG = document.createElement("img");

			oIMG.src = this.icon.item;
			oIMG.alt = ""; //alt-text on item img
			if (this.icon.align == "left") {
				oLI.insertBefore(oIMG,oLI.firstChild);	// 
				//oLI.insertBefore(oIMG,oLI.firstChild);	
			} else {
				oLI.insertBefore(oIMG,oLI.firstChild.nextSibling);	
			}
		}
	};							
_h.Tree.prototype.toggle = function (oLI) {
		if (oLI._hTree_folder == true) {
			if (oLI._hTree_open == true) { 
				this.collapse(oLI); 
			} else { 
				if (this.oneSibling == true) {
					this.closeSiblings(oLI);
				}
				this.expand(oLI); 
			}
		}
	};
_h.Tree.prototype.collapse = function (oLI) {
		var oIMG = oLI._hTree_oIMG;
		var oUL	= oLI._hTree_oUL;
	
		oUL.style.display = "none";
		if (oIMG) {
			oIMG.src = this.icon.closed;
			oIMG.alt = "+";
		}
		oLI._hTree_open = false;
		_h.setCookie(oUL.id, "0", this.cookiePath); 
}	
_h.Tree.prototype.expand = function (oLI) {
		var oIMG = oLI._hTree_oIMG;
		var oUL	= oLI._hTree_oUL;

		oUL.style.display = "block";  
		if (oIMG) {
			oIMG.src = this.icon.open;
			oIMG.alt = "-";
		}
		oLI._hTree_open = true;
		_h.setCookie(oUL.id, "1", this.cookiePath);
}	
_h.Tree.prototype.select = function(oLI) {
		if (oLI._hTree_oLink)
			oLI._hTree_oLink.focus()
};
_h.Tree.prototype.closeSiblings = function(oLI) {
		var oUL = oLI.parentNode;
		for (var x=oUL.childNodes.length-1; x >= 0; x--) {
			if (oUL.childNodes[x].nodeType == 3) { continue; } //TEXT_NODE
			if (oUL.childNodes[x] != oLI) {
				if (oUL.childNodes[x]._hTree_open) {
					this.collapse(oUL.childNodes[x]);
				}
			}
		}
};
_h.Tree.prototype.getNextLI = function(oLI) {
		var oUL = oLI.parentNode;
		var bCurrentLI = false;
		for (var x=0; x < oUL.childNodes.length; x++) {
			if (oUL.childNodes[x].nodeType == 3) { continue; } //TEXT_NODE
			if (oLI == oUL.childNodes[x]) {
				bCurrentLI = true;
				continue;
			}
			if (bCurrentLI == true) {
				return oUL.childNodes[x];
			}
		}
		return this.getNextLI(oUL.parentNode);
};
_h.Tree.prototype.getPrevLI = function(oLI) {
		var oUL = oLI.parentNode;
		var bCurrentLI = false;
		for (var x=oUL.childNodes.length-1; x >= 0; x--) {
			if (oUL.childNodes[x].nodeType == 3) { continue; } //TEXT_NODE
			if (oUL.childNodes[x] == oLI) {
				bCurrentLI = true;
				continue;
			}
			if (bCurrentLI == true) {
				if (oUL.childNodes[x]._hTree_open) {
					return this.getLast(oUL.childNodes[x]);
				} else {
					return oUL.childNodes[x];
				}
			}
		}
		return oUL.parentNode;
};
_h.Tree.prototype.getLast = function(oLI) {
		var oUL = oLI._hTree_oUL;
		for (var x=oUL.childNodes.length-1; x >= 0; x--) {
			if (oUL.childNodes[x].nodeType == 3) { continue; } //TEXT_NODE
			if (oUL.childNodes[x]._hTree_open) {
				return this.getLast(oUL.childNodes[x]);
			} else {
				return oUL.childNodes[x];
			}
		}
};
_h.Tree.prototype._keyNavigation = function(code, oLI) {	
		if ((code == 37) || (code == 38) || (code == 39) || (code == 40)) {
			var oIMG = oLI._hTree_oIMG;
			var oUL	= oLI._hTree_oUL;
			
			if (code == 37) { /* Left */
				if (oLI._hTree_open) {
					this.toggle(oLI);
				} else {
					this.select(oLI.parentNode.parentNode);
				}
			} else if (code == 38) { /* Up */
				var oLI_prev =  this.getPrevLI(oLI); 
				if (oLI_prev) { this.select(oLI_prev);}
				return false;
			} else if (code == 39) { /* Right */
				if (oLI._hTree_open) {
					if (oLI.getElementsByTagName("li")) {
						this.select(oLI.getElementsByTagName("li")[0])
					}
				} else {
					this.toggle(oLI);
				}
			} else if (code == 40) { /* Down */
				if (oLI._hTree_open) {
					if (oLI.getElementsByTagName("li")) {
						this.select(oLI.getElementsByTagName("li")[0])
					}
				} else {
					var oLI_next = this.getNextLI(oLI);
					if (oLI_next) { this.select(oLI_next); }
				}
			}
		} else {
			return true;
		}
};


// Helper functions
_h.getCookie = function(name) { 
	var arg = name + "=";  
	var alen = arg.length;  
	var clen = document.cookie.length;  
	var i = 0;  
	while (i < clen) {
		var j = i + alen;    
		if (document.cookie.substring(i, j) == arg) {
			var endstr = document.cookie.indexOf (";", j);
			if (endstr == -1) endstr = document.cookie.length;
			return unescape(document.cookie.substring(j, endstr));
 		}
		i = document.cookie.indexOf(" ", i) + 1;    
		if (i == 0) break;   
	}  
	return null;
}
_h.setCookie = function(key, value, path) {
	document.cookie= key + "=" + escape(value) + ((path) ? "; path=" + path : "");
}
_h.hasClass = function (el, className) {
	var cs, j
	cs = el.className.split(" ");
	for (j = 0; j < cs.length; j++) {
		if (cs[j] == className) {
			return true;
		}
	}
	return false;
} 
_h.addClass = function (el, className) {
	if (el.className==null) 
		el.className='';
	el.className+=(el.className.length>0?' ':'')+className;
}
_h.removeClass = function (el, className) {
  var cs, j, remainClass
  remainClass = new Array();
  cs = el.className.split(" ");
  for (j = 0; j < cs.length; j++) {
    if (cs[j] != className) {
      remainClass.push(cs[j]);
	 }
  }
  el.className = remainClass.join(" ");
}
_h.addEvent = function (oEl, sEvent, sFunction, useCapture) {	
	if (oEl) {
		if (oEl.addEventListener) { // MOZ
			oEl.addEventListener(sEvent,sFunction,useCapture);
			return true;
		} else if (oEl.attachEvent) { // IE5
			var r = oEl.attachEvent("on"+sEvent,sFunction);
			return r;
//		} else if (document.all) { // IE4
//			eval('oEl.on'+sEvent+'='+sFunction+';');
//		} else {
//		  alert("Handler could not be attached");
		}
	}
}

// Array.push() - Add an element to the end of an array
if (typeof(Array.prototype.push) == 'undefined') {
  Array.prototype.push = function() {
  	var currentLength = this.length;
  	for (var i = 0; i < arguments.length; i++) {
  		this[currentLength + i] = arguments[i];
  	}
  	return this.length;
  };
}

//**************************// FAQ expand / collapse  END //************************************

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImg1() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; 
  document.MM_sr=new Array; 
  for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null)
   {
   	document.MM_sr[j++]=x;
   	if(!x.oSrc) 
   		x.oSrc=x.src; 
   	x.src=a[i+2];
   }
}

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];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; 
  document.MM_sr=new Array; 
  for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null)
   {
   	document.MM_sr[j++]=x;
   	if(!x.oSrc) x.oSrc=x.src; 
   	x.src=a[i+2];
   }
}
/*-----------------------------*/

function changeNewImage(imageDiv) {
	var elements = document.getElementsByTagName("img");
	for (var i=0; i<elements.length;i++) {
		if (elements[i].className==imageDiv) {
			addEvent(elements[i], 'mouseover', loadNewImage, false);
		}
	}			
}

function loadNewImage(e) {
	var element = window.event ? window.event.srcElement : e ? e.target : null;
	var imgName=getImgName(element.src);
	var newImgName=getNewImgName(imgName);
	//alert(newImgName);
	element.src=getImgPath(element.src)+getImgPathSize(element.src) + '/' + newImgName;
}

function getNewImgName(oldName) {
	var clkSlash = oldName.lastIndexOf(".");
	var oldImageExt = oldName.slice(clkSlash+1, oldName.length);
	var oldImageName = oldName.slice(0,clkSlash);
	if(oldName.slice(clkSlash-2,clkSlash)!='_o')
		return oldImageName + '_o.' + oldImageExt;
	else
		return oldName;
}

/*-----------------------------*/

function changeOldImage(imageDiv) {
	var elements = document.getElementsByTagName("img");
	for (var i=0; i<elements.length;i++) {
		if (elements[i].className==imageDiv) {
			addEvent(elements[i], 'mouseout', loadOldImage, false);
		}
	}			
}

function loadOldImage(e) {
	var element = window.event ? window.event.srcElement : e ? e.target : null;
	var imgName=getImgName(element.src);
	var newImgName=getOldImgName(imgName);
	element.src=getImgPath(element.src)+getImgPathSize(element.src) + '/' + newImgName;
}

function getOldImgName(imgName) {
	var clkSlash = imgName.lastIndexOf(".");
	var oldImageExt = imgName.slice(clkSlash+1, imgName.length);
	var oldImageName = imgName.slice(0,clkSlash-2);
	if(imgName.slice(clkSlash-2,clkSlash)!='_o')
		return imgName;
	else
		return oldImageName + '.' + oldImageExt;
}

function fixHeader(){
	var elements = document.getElementsByTagName("img");
	var hspacer= new Array(7);
	var j=0;
	for (var i=0; i<elements.length;i++) {
		if (elements[i].id=='hspacer') {
			hspacer[j]=elements[i];
			j++;
		}
	}			
	if(hspacer.length==7){
		var element = hspacer[0];
		element.src='';
		element.width='0';
		element.height='0';
	}
}

function ShowNextImage(id, index,pInfo)
{
	index--;
	if(index < 0)
	{
		index = pInfo.length-1;				
	}			
	var a = document.getElementById(id+'_currentImage');
	var prc = document.getElementById(id+'_currentPrice');
	a.innerHTML = pInfo[index].productImage;	
	a.href = pInfo[index].productLink;		
	prc.innerHTML = "Now Only: " + pInfo[index].productPrice;	
	document.getElementById(id+'_productLinkId').innerHTML = pInfo[index].productDisplayName;
	document.getElementById(id+'_productLinkId').href = pInfo[index].productLink;
	return index;
}

function ShowPreviousImage(id, index,pInfo)
{	
	index++;
	if(index >pInfo.length-1)
	{
			index =0;	
	}				    		
	var a = document.getElementById(id+'_currentImage');
	var prc = document.getElementById(id+'_currentPrice');
	a.innerHTML = pInfo[index].productImage;	
	a.href = pInfo[index].productLink;				    
	prc.innerHTML = "Now Only: " + pInfo[index].productPrice;	
	document.getElementById(id+'_productLinkId').innerHTML = pInfo[index].productDisplayName;
	document.getElementById(id+'_productLinkId').href = pInfo[index].productLink;					
	return index;
}