if (document.createElement && document.getElementsByTagName && document.getElementById) {
if (window.addEventListener) window.addEventListener('load', setupScripts, false);
else if (window.attachEvent) window.attachEvent('onload', setupScripts);
}

function setupScripts()
{
     //Dropdown Menu
		if (navigator.appVersion.match(/\bMSIE\b/))
		{     
			
 
			applyDropDownF('full','topnavigation_r','',true,1,-495,4,'hoveredspan',800,500,1,22,15);
		}
		else
		{
		    applyDropDownF('full','topnavigation_r','',true,1,-415,15,'hoveredspan',600,350,1,22,15);
		}
}

var apP = new Array() , pcdR = new Array();
apP.earlyDivId = 'earlymenu';
apP.earlyStyle = 'position:left;width:240px;height:auto;padding:0em:1em;border:3px solid black;background-color:white;font-size:12px;z-index:100;visibility:hidden;'
apP.preload = true;
apP.divIds = new Array ("menucontainer","menucontent","menucontdouble","menubottom","menuboxmodeltest","menutop");


function writeEarlyDrop()
{
    document.write("<div id='"+apP.earlyDivId+"' style='"+apP.earlyStyle+"'></div>");
}

//applyDropDownF('early','topnavigation','topnavigation_r',true,1,-10,0,'hoveredspan',450,150);
function applyDropDownF( procType, tElId, navIdRep, fxBdMrgn, mLoc, xOf, yOf, hvrCl, hiDly, whiDly, rSty, rStps, rvInt )
{

	if (document.getElementById(tElId))
 	{
        //alert( procType );
		var dGv = new Array(), dOb = new Array(), revSteps, early;
		dOb.revStep = 0;
		dOb.revInt = new Array();


		if (fxBdMrgn == true && document.body.style)
            document.body.style.margin = '0px';
		if (pcdR.hoverParent)
    {
        pcdR.hoverParent.className = pcdR.hoverParent.revClass;
    }
		var BMdependency = new Array (true,true,false);
		early = (procType != 'early') ? false : true;
		var targetList = document.getElementById(tElId);
		//var ulLis = targetList.getElementsByTagName("ul");
		var spLis = targetList.getElementsByTagName("span");
		//var spLis = targetList.getElementsById("cartTitle");
		if (navIdRep != '')
            targetList.id = navIdRep;
		if (procType != 'early')
    {
       // alert( procType );
        var bMO = addDropdownDiv();
    }
		else
    {
        //alert( procType );
        pcdR.tDiv = document.getElementById(apP.earlyDivId);
        pcdR.cDiv = pcdR.tDiv;
		pcdR.tDiv.onmouseover = keepAlive;
				pcdR.tDiv.onclick = keepAlive;		
        pcdR.tDiv.onmouseout = hideDrop;
    }

		if (targetList.listHolder)
    {
			var cTM = targetList.listHolder.childNodes, tE = cTM.length
			for (var i = 0; i < tE; i++)
      {
          pcdR.cDiv.appendChild(cTM[0]);
      }
		}
		targetList.listHolder = pcdR.cDiv;
		
		for (var i=0; i<spLis.length; i++)
    {
			var newBranch = spLis[i].parentNode.getElementsByTagName('ul');
			if (newBranch.length > 0 || spLis[i].processed)
      {
                //prompt( newBranch[0].innerHTML, procType );
				if (!spLis[i].processed) 
				    spLis[i].expcol = newBranch[0];
				spLis[i].expcol.style.display = 'none';
				spLis[i].revClass = spLis[i].className;
				if (mLoc == 2) spLis[i].positionSubMenu = posRight;
				else spLis[i].positionSubMenu = posUnder;

				spLis[i].onmouseover = showDrop;
				spLis[i].onclick = showDrop;
				spLis[i].onmouseout = hideDrop;
				if ( !early )
        { 
					if ( bMO == true && BMdependency[ rSty ] == true )
                        revSteps = 0;
					else
                        revSteps = rStps;
					if (rSty == 2)
                        spLis[i].reveal = sliderInit;
					else if (rSty == 1)
                        spLis[i].reveal = warperInit;
					else
                        spLis[i].reveal = placeDrop;
					if (revSteps == 0)
                        spLis[i].reveal = placeDrop;
				}
        else
        { 
					spLis[i].reveal = placeDrop;
          revSteps = 0;
				}
				if ( !spLis[i].processed )
          pcdR.cDiv.appendChild(newBranch[0]);

				spLis[i].processed = true;
			}
		}
	} else return;


function showDrop()
{
	window.clearTimeout(dOb.hidetimer);
	clearRevIntervals();
	dOb.revStep = 0;
	if (pcdR.hoverParent)
        pcdR.hoverParent.className = pcdR.hoverParent.revClass;
	this.className = hvrCl; 
    pcdR.tDiv.style.clip = 'rect(auto auto auto auto)';
	if( pcdR.displayed )
        pcdR.displayed.style.display = 'none';
	pcdR.displayed = this.expcol;
	this.expcol.style.display = 'block';
	pcdR.hoverParent = this;
	dOb.subMenuPos = this.positionSubMenu();
	document.body.style.cursor = 'pointer';
	this.reveal();

}

function placeDrop()
{

	if (revSteps == 0 && !early)
        pcdR.dDiv.style.height = pcdR.cDiv.offsetHeight+'px';
	pcdR.tDiv.style.left = dOb.subMenuPos[0]+"px";
	pcdR.tDiv.style.top =  dOb.subMenuPos[1]+"px";
	if (navigator.appVersion.match(/\bMSIE\b/))
     pcdR.tDiv.style.left  = "316px";
	else
	 pcdR.tDiv.style.left  = "324px";

  	pcdR.tDiv.style.visibility = 'visible';
	
	
}

function warperInit()
{
	placeDrop();
	pcdR.dDiv.style.height = '0px';
	dOb.tHeight = pcdR.cDiv.offsetHeight;
	dOb.revInt[dOb.revInt.length] = window.setInterval(
		function(){
			if (dOb.revStep < revSteps+1) {
			pcdR.dDiv.style.height = easeInOut(0,dOb.tHeight,revSteps,dOb.revStep,0.5) + "px";
			dOb.revStep++;
			} else clearRevIntervals();
		},rvInt);
}

function sliderInit()
{
	pcdR.tDiv.style.clip = 'rect(0 0 0 0)';
	placeDrop();
	pcdR.dDiv.style.height = 'auto';
	dOb.tWidth = pcdR.tDiv.offsetWidth;
	dOb.tHeight = pcdR.tDiv.offsetHeight;
	if (!early) pcdR.dDiv.style.height = pcdR.cDiv.offsetHeight;
	dOb.revInt[dOb.revInt.length] = window.setInterval(
		function() {
			if (dOb.revStep < revSteps) {
			var yLevel = easeInOut(0,dOb.tHeight,revSteps,dOb.revStep,0.5);
			pcdR.tDiv.style.clip = 'rect(0px '+dOb.tWidth+'px '+yLevel+'px 0px)';
			
			dOb.revStep++;
			} else {pcdR.tDiv.style.clip = 'rect(auto auto auto auto)'; clearRevIntervals();}
		},rvInt)

}

function hideDrop()
{
	if (!pcdR.hoverParent) return;
	document.body.style.cursor = 'auto';
	var hideDelay = (revSteps > 0 && dOb.revStep < revSteps && revSteps != 0) ? whiDly : hiDly
	dOb.hidetimer = window.setTimeout(function() {
		if (revSteps > 0) clearRevIntervals();
		pcdR.tDiv.style.visibility = 'hidden';
		pcdR.hoverParent.className = pcdR.hoverParent.revClass;
		},hideDelay);
}


function keepAlive()
{
    //alert( "yo" );
    window.clearTimeout(dOb.hidetimer);
}

function posUnder()
{
    var elmPos = findPos(this);

    return Array (elmPos[0]+xOf,elmPos[1]+this.offsetHeight+yOf)
}

function posRight()
{
    var elmPos = findPos(this);
    return Array (elmPos[0]+xOf+this.offsetWidth,elmPos[1]+yOf)
}

function clearRevIntervals()
{
    for (i=0;i<dOb.revInt.length;i++)
        window.clearInterval(dOb.revInt[i]);
    dOb.revInt = new Array();
}

function addDropdownDiv()
{
	if (document.getElementById(apP.earlyDivId))
        document.getElementById(apP.earlyDivId).parentNode.removeChild(document.getElementById(apP.earlyDivId));
	var ttDiv = new Array(), prefix = "", boxModelOld = false;
	if (apP.useDefStyle==true) prefix = "M_"
	for (var i=0;i<apP.divIds.length;i++)
    {
		if (document.getElementById(apP.divIds[i]) != null)
            document.getElementById(apP.divIds[i]).parentNode.removeChild(document.getElementById(apP.divIds[i]));
		ttDiv[i]=document.createElement('div');
		ttDiv[i].id = prefix + apP.divIds[i];
		ttDiv[i].activeStyle = dGetActiveStyle;
	}
	var c = new Array("margin","padding","border","top","left")
	for (i=0;i<c.length;i++)
    {
        eval("ttDiv[2].style."+c[i]+" = '0px'");
        eval("ttDiv[4].style."+c[i]+" = '0px'");
        eval("ttDiv[0].style."+c[i]+" = '0px'")
    }

	ttDiv[2].style.position = "relative";
    ttDiv[2].style.width = "100%";
	ttDiv[4].style.visibility = "hidden";
    ttDiv[4].style.position = "absolute";
	ttDiv[0].style.visibility = "hidden";
    ttDiv[0].style.position = "absolute";
	ttDiv[1].appendChild(ttDiv[2]);
    ttDiv[0].appendChild(ttDiv[1]);
    ttDiv[0].appendChild(ttDiv[3]);
	ttDiv[0].insertBefore(ttDiv[5],ttDiv[1]);
	document.body.appendChild(ttDiv[0]);

	for (var i=0;i<apP.divIds.length;i++)
    {
		var bgIm = ttDiv[i].activeStyle("background-image","backgroundImage");
		if (bgIm.indexOf("url") > -1 && apP.preload == true)
            dPreLoadImage(dStripURL(bgIm))
	}
	document.body.appendChild( ttDiv[4] )
	ttDiv[1].style.overflow = "hidden";
	ttDiv[4].style.padding = "10px";
    ttDiv[4].style.height = "100px";
	if (ttDiv[4].offsetHeight == 100)
        boxModelOld = true;
	document.body.removeChild(ttDiv[4]);

	for(var i=3;i<6;i+=2)
    {
    	ttDiv[i].innerHTML = "&nbsp;";
    	if (window.getComputedStyle && ttDiv[i].activeStyle('background-image','').indexOf("url") == -1)
    		ttDiv[0].removeChild(ttDiv[i]);
    	else if (ttDiv[i].currentStyle && (ttDiv[i].currentStyle.backgroundImage.indexOf("url") == -1 && ttDiv[i].currentStyle.filter.indexOf("AlphaImageLoader") == -1))
    		ttDiv[0].removeChild(ttDiv[i]);
	}
	if (apP.useDefStyle == true)
    {
		ttDiv[0].style.width = apP.defWidth;
		ttDiv[0].style.zIndex = apP.defZindex;
		for (var i=0;i<apP.defCSS.length;i+=2) eval("ttDiv[1].style."+apP.defCSS[i]+"='"+apP.defCSS[i+1]+"'");
	}
	pcdR.cDiv = ttDiv[2];
    pcdR.tDiv = ttDiv[0];
    pcdR.dDiv = ttDiv[1];
	pcdR.tDiv.onmouseover = keepAlive;
	pcdR.tDiv.onmouseout = hideDrop;

	return boxModelOld;
}


function dGetActiveStyle(style,stylecc)
{
    if (window.getComputedStyle)
        return window.getComputedStyle(this,null).getPropertyValue(style);
    if (this.currentStyle)
        return eval("this.currentStyle."+stylecc);
    return '';
}

function dStripURL(s)
{
    s = s.substring(s.indexOf("url(")+4,s.lastIndexOf(")"));if (s.indexOf('"')>-1) s = s.substring(s.indexOf('"')+1,s.lastIndexOf('"'));return s;
}

function dPreLoadImage(imageurl)
{
    var img = new Image();
    img.src = imageurl;
    return img;
}

function findPos(obj)
{
    //function modified from www.quirksmode.org
    var curleft = 0;
    var curtop = 0;
    if (obj.offsetParent)
    {
    	while (obj.offsetParent)
        {
    		curleft += obj.offsetLeft
    		curtop += obj.offsetTop
    		obj = obj.offsetParent;
    	}
    }
    else if (obj.x && obj.y)
    {
        curleft += obj.x;
        curtop += obj.y;
    }
    return Array(curleft,curtop);
}


}

function easeInOut(minValue,maxValue,totalSteps,actualStep,powr){
//Generic Animation Step Value Generator By www.hesido.com
var delta = maxValue - minValue;
var stepp = minValue+(Math.pow(((1 / totalSteps)*actualStep),powr)*delta);
return Math.ceil(stepp)
}