

// 		Insert Flash into page - bypasses IE ELOS patent
//
function flashInsert(movie, w, h) {

var v_flash = flashDetect();
if(v_flash) {
	document.write('<object type="application/x-shockwave-flash" data="'+movie+'.swf" width="'+w+'" height="'+h+'">');
	document.write('<param name="movie" value="'+movie+'.swf" />');
	document.write('<param name="wmode" value="transparent" />');
	document.write('<param name="autoStart" value="-1"></object>');

}
else {
	document.write('<img src="'+movie+'.jpg" width="'+w+'" height="'+h+'" alt="" />');
}

}




//		 Check if flash player is present / up-to-date
//
function flashDetect() {
  var flashVersion = new Array();

  flashVersion["major"] = 0;
  flashVersion["build"] = 0;


  if (navigator.plugins && typeof navigator.plugins["Shockwave Flash"] == "object")
  {
    var description = navigator.plugins["Shockwave Flash"].description;

    if (description != null)
    {
      var versionString = description.replace(/^.*\s+(\S+\s+\S+$)/, "$1");

      flashVersion["major"] = parseInt(versionString.replace(/^(.*)\..*$/, "$1"));
      flashVersion["build"] = parseInt(versionString.replace(/^.*r(.*)$/, "$1"));
    }
  }
  else if (typeof window.ActiveXObject != "undefined")
  {
    try
    {
      var flashObject = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
      var description = flashObject.GetVariable("$version");

      if (description != null)
      {
        var versionNumbers = description.replace(/^\S+\s+(.*)$/, "$1").split(",");

        flashVersion["major"] = parseInt(versionNumbers[0]);
        flashVersion["build"] = parseInt(versionNumbers[2]);
      }
    }
    catch(error)
    {
    }
  }



  if(navigator.userAgent.indexOf('Linux') != -1) {
// 	return false;
  }

  if (flashVersion["major"] > 6) {
	return true;
  }
  else {
	return false;
  }

}

function externalLinks() {

  var theLinks = document.links;

	if (!document.links)
		{
		document.links = document.getElementsByTagName('a');
		}


var thisDomain = window.location.hostname;


	for (i=0; i < theLinks.length; i++) {
		var thisLink = theLinks[i];
		  if (thisLink.href.indexOf(thisDomain) == -1 && thisLink.href.indexOf("javascript") == -1) {
    			thisLink.target = "_blank";
   			}
  	}
}

addEvent(window,'load',externalLinks);

function showLocation(loc) {
	alert("You are located in: "+loc);
}






/*
	tableruler()
	written by Chris Heilmann for alistapart.
	enables a rollover of rows for each table with the classname "hlrows"
*/

function tableruler()
{
	if (document.getElementById && document.createTextNode)
	{
		var tables=document.getElementsByTagName('table');
		for (var i=0;i<tables.length;i++)
		{
			if(tables[i].className=='ruler')
			{
				var trs=tables[i].getElementsByTagName('tr');
				for(var j=0;j<trs.length;j++)
				{
					if(trs[j].parentNode.nodeName=='TBODY')
					{
						trs[j].onmouseover=function(){this.className='ruled';return false}
						trs[j].onmouseout=function(){this.className='';return false}
					}
				}
			}
		}
	}
}

addEvent(window,'load',tableruler);

// tip of the hat to http://www.paulbellows.com/getsmart/balance_columns/
function setTall() {
	if (document.getElementById) {
		// the divs array contains references to each column's div element.  
		// Replace 'center' 'right' and 'left' with your own.  
		// Or remove the last one entirely if you've got 2 columns.  Or add another if you've got 4!
		var divs = new Array(document.getElementById('main_content'), document.getElementById('rightnav'), document.getElementById('leftnav'));
		
		// Let's determine the maximum height out of all columns specified
		var maxHeight = 0;
		for (var i = 0; i < divs.length; i++) {
			if (divs[i].offsetHeight > maxHeight) maxHeight = divs[i].offsetHeight;
		}
		
		// Let's set all columns to that maximum height
		for (var i = 0; i < divs.length; i++) {
			divs[i].style.height = maxHeight + 'px';

			// Now, if the browser's in standards-compliant mode, the height property
			// sets the height excluding padding, so we figure the padding out by subtracting the
			// old maxHeight from the new offsetHeight, and compensate!  So it works in Safari AND in IE 5.x
			if (divs[i].offsetHeight > maxHeight) {
				divs[i].style.height = (maxHeight - (divs[i].offsetHeight - maxHeight)) + 'px';
			}
		}
	}
}

addEvent(window, 'load', setTall, false);
addEvent(window, 'resize', setTall, false);



/*
	pinballEffect()
	written by Adam Khan.
	http://www.digital-web.com/articles/the_pinball_effect/
*/
var W3CDOM = (document.createElement && document.getElementsByTagName);
function pinballEffect()
{
	if (!W3CDOM) return;
	var allElements = document.getElementsByTagName('*');
	var originalBackgrounds=new Array();
	for (var i=0; i<allElements.length; i++)
	{
		if (allElements[i].className.indexOf('pinball-scoop') !=-1)
		{
			allElements[i].onmouseover = mouseGoesOver;
			allElements[i].onmouseout = mouseGoesOut;
			allElements[i].onclick = mouseGoesClick;
		}
	}
}

function mouseGoesOver()
{

	originalClassNameString = this.className;
	this.className += " pinball-on";
	this.style.cursor = "pointer";
	this.style.cursor = "hand";

	var changeHeader = this.getElementsByTagName('h4');
	for (var j=0; j<changeHeader.length; j++)
	{
		if (changeHeader[j].className.indexOf('product_title') != -1)
		{
// 			alert(changeHeader[j].innerHTML);
// 			changeHeader[j].style.visibility = 'none';
			addClass(changeHeader[j], "title_green");
// 			alert(changeHeader[j]);
		}
	}


}

function mouseGoesOut()
{
	this.className = originalClassNameString;
	var changeHeader = this.getElementsByTagName('h4');
	for (var j=0; j<changeHeader.length; j++)
	{
		if (changeHeader[j].className.indexOf('product_title') != -1)
		{
// 			alert(changeHeader[j].innerHTML);
// 			changeHeader[j].style.visibility = 'none';
			removeClass(changeHeader[j], "title_green");
// 			alert(changeHeader[j]);
		}
	}
}

function mouseGoesClick()
{
	var allThisAreasElements = this.getElementsByTagName('*');
	for (var j=0; j<allThisAreasElements.length; j++)
	{
		if (allThisAreasElements[j].className.indexOf('pinball-sinkhole') != -1)
		{
			var url = allThisAreasElements[j].href;
			window.location = url;
		}
	}
}

addEvent(window,'load',pinballEffect);



function fadeOut(elemId, fade) {

  var elementDiv = document.getElementById(elemId);
  elementDiv.style.backgroundColor = "rgb(100%, 100%, "+fade+"%)";
//   alert(elementDiv.style.backgroundColor);
  fade = fade + 10;
   if (fade <= 100) 
   {
     window.setTimeout("fadeOut('"+elemId+"',"+fade+")", 150);
   }
}


function addClass(target, classValue)
{
    if (!hasClass(target, classValue))
    {
        if (target.className == "")
        {
            target.className = classValue;
        }
        else
        {
            target.className += " " + classValue;
        }
    }

    return true;
};




function removeClass(target, classValue)
{
    var removedClass = target.className;
    var pattern = new RegExp("(^| )" + classValue + "( |$)");

    removedClass = removedClass.replace(pattern, "$1");
    removedClass = removedClass.replace(/ $/, "");

    target.className = removedClass;

    return true;
};




function hasClass(target, classValue)
{
    var pattern = new RegExp("(^| )" + classValue + "( |$)");
    
    if (target.className.match(pattern))
    {
    	return true;
    }
    
    return false;
};

