/* determining whether msie or netscape being used and what versions */
var IE4 = (document.all && !document.getElementById) ? 1 : 0;
var NS4 = (document.layers) ? 1 : 0;
var IE5 = (document.all && document.getElementById) ? 1 : 0;
var N6 = (document.getElementById && !document.all) ? 1 : 0;
var ie = (IE4 || IE5) ? 1 : 0;
var n = (NS4 || N6) ? 1 : 0;

var IE5MAC = false;
var NS4MAC = false;

var platformTypeNT = navigator.appVersion.indexOf("Windows NT")>0
var platformTypeXP = navigator.appVersion.indexOf("Windows NT 5.1")>0
var platformTypeWin98 =  navigator.appVersion.indexOf("Windows 98")>0
var ieVer6 = navigator.appVersion.indexOf("6")>0
var ieVer5 = navigator.appVersion.indexOf("5")>0
var MAC = (navigator.userAgent.indexOf("Mac")) // determines platform

//Detect IE5.5+
version=0
if (navigator.appVersion.indexOf("MSIE")!=-1){
temp=navigator.appVersion.split("MSIE")
version=parseFloat(temp[1])
}

if (MAC != -1)
{
	if (IE5)
	{
		IE5MAC = true; //determines if ie5 on a mac
	}
	else
	{
		if (NS4 || N6)
		{
			NS4MAC = true; // determines if net 4 or 6 on mac
		}
	}
}
else
{
}

var ROClass = NS4 || IE5MAC ? '' : ' class="swatchDivClass"';

var isDHTML = 0;
var isID = 0;
var isAll = 0;
var isLayers = 0;

if (document.getElementById)
{
	isID = 1;
	isDHTML = 1;
}
else
{
	if (document.all)
	{
		isAll = 1;
		isDHTML = 1;
	}
	else
	{
		browserVersion = parseInt(navigator.appVersion);
		if ((navigator.appName.indexOf('Netscape') != -1) && (browserVersion == 4))
		{
			isLayers = 1;
			isDHTML = 1;
		}
	}
}

function findDOM(objectID,withStyle) {
	if (withStyle == 1) {
		if (isID) { return (document.getElementById(objectID).style) ; }
		else { 
			if (isAll) { return (document.all[objectID].style); }
		else {
			if (isLayers) { return (document.layers[objectID]); }
		};}
	}
	else {
		if (isID) { return (document.getElementById(objectID)) ; }
		else { 
			if (isAll) { return (document.all[objectID]); }
		else {
			if (isLayers) { return (document.layers[objectID]); }
		};}
	}
}

// gets y coordinate for IE and Net - but doesn't work for Mac IE
function findTop(objectID) {
	var domStyle = findDOM(objectID,1);
	var dom = findDOM(objectID,0);
	if (dom.offsetTop)
		return dom.offsetTop;
	if (domStyle.top)
		return domStyle.top;
	if (domStyle.pixelTop)
		return domStyle.pixelTop;
	return (null);
}

// gets x coordinate for IE and Net - but doesn't work for Mac IE
function findLeft(objectID) {
	var domStyle = findDOM(objectID,1);
	var dom = findDOM(objectID,0);
	if (dom.offsetLeft)
		return dom.offsetLeft;
	if (domStyle.left)
		return domStyle.left;
	if (domStyle.pixelLeft)
		return domStyle.pixelLeft;
	return (null);
	
}

// gets x coordinate for IE - need to use this one for Mac IE
function DL_GetElementLeft(eElement)
{
    if (!eElement && this)                       
    {                                            
        eElement = this;                         
    }                                           
    
    var nLeftPos = eElement.offsetLeft;         
    var eParElement = eElement.offsetParent;    
    while (eParElement != null)
    {                                            
        nLeftPos += eParElement.offsetLeft;
		eParElement = eParElement.offsetParent; 
    }
		return nLeftPos;		                             
}

// gets y coordinate for IE- - need to use this one for Mac IE
function DL_GetElementTop(eElement)
{
    if (!eElement && this)
    {
        eElement = this;
    }

    var nTopPos = eElement.offsetTop;
    var eParElement = eElement.offsetParent;
    while (eParElement != null)
    {
    	nTopPos += eParElement.offsetTop;
        eParElement = eParElement.offsetParent;
       
    }
    
  
    return nTopPos;
}

tempArraySwatch = new Array();

// function to move positions of layers around screen for swatch
function swatchOn(objectID,widthSet,swatchDiv,swatchDivHeader,swatchDivLeft,swatchDivRight)
{
	if(IE4 || IE5)
	{
		if (!IE5MAC)
		{
			tempArraySwatch2 = new Array(swatchDiv);
			tempArraySwatch = tempArraySwatch.concat(tempArraySwatch2);
			for (var i=0;i<tempArraySwatch.length;i++)
			{
				if (eval(tempArraySwatch[i]).style) eval(tempArraySwatch[i]).style.visibility = "hidden";
			}		
			widthSet = eval(widthSet);
			heightSet = eval(widthSet);		
			widthSet = (widthSet.width + 20);
			tableHeader = document.getElementById(swatchDivHeader);
			tableHeader.setAttribute("width",widthSet);  // changes table attributes
			heightSetLeft = (heightSet.height + 45);
			tdLeft = document.getElementById(swatchDivLeft);
			tdRight = document.getElementById(swatchDivRight);		
			tdLeft.setAttribute("height",heightSetLeft); // changes table attributes		
			tdRight.setAttribute("height",heightSetLeft);	 // changes table attributes			
			objectID = eval(objectID);
			var nMyElementsTrueXPosition = DL_GetElementLeft(objectID); // for ie		
			var nMyElementsTrueYPosition = DL_GetElementTop(objectID); // for ie
			swatchPosX = (nMyElementsTrueXPosition - 10); // for ie
			swatchPosY = (nMyElementsTrueYPosition - 10);	// for ie
			swatchDiv = eval(swatchDiv);
		}	
		if (IE5MAC)
		{
			//swatchDiv.style.offsetLeft = swatchPosX; // moves swatch into correct position
			//swatchDiv.style.offsetTop = swatchPosY; // moves swatch into correct position				
		}
		else
		{
			//if (version==5.5 || (platformTypeWin98 && version >= 5.5) || (platformTypeXP && version >= 5.5))
			//{
				// no idea why ie 6 on win 98 gets wrong top value but it does 
				//swatchDiv.style.pixelLeft = swatchPosX-2; // moves swatch into correct position
				//swatchDiv.style.pixelTop = ((swatchPosY / 2)+8); // moves swatch into correct position	
			//}
			//else
			//{
				swatchDiv.style.left = swatchPosX + "px"; // moves swatch into correct position
				swatchDiv.style.top = swatchPosY + "px"; // moves swatch into correct position					
			//}	
		}
		if (IE5MAC)
		{
	
		}
		else
		{		
			swatchDiv.style.visibility = "visible";		
			swatchDivClose = swatchDiv;	// sets global variable
		}
	}
	if (N6)
	{

		tempArraySwatch.unshift(swatchDiv);
		for (var i=0;i<tempArraySwatch.length;i++)
		{
			document.getElementById(tempArraySwatch[i]).style.visibility = "hidden";
		}			
		leftPos = findLeft(objectID); // for n
		topPos = findTop(objectID); // for n
		swatchPosX = (leftPos - 10); // for ie
		swatchPosY = (topPos - 10);	// for ie
		swatchDiv = swatchDiv.toString(10);
		document.getElementById(swatchDiv).style.left = swatchPosX + "px"; // moves swatch into correct position
		document.getElementById(swatchDiv).style.top = swatchPosY + "px"; // moves swatch into correct position
		document.getElementById(swatchDiv).style.visibility = "visible";
		widthSet = widthSet.toString(10);
		heightSet = widthSet.toString(10);			
		widthSet = (document.getElementById(widthSet).width + 20);
		var tableHeader = document.getElementById(swatchDivHeader);
		tableHeader.setAttribute("width",widthSet);  // changes table attributes
		heightSetLeft = (document.getElementById(heightSet).height + 40);
		var tdLeft = document.getElementById(swatchDivLeft);
		var tdRight = document.getElementById(swatchDivRight);		
		tdLeft.setAttribute("height",heightSetLeft);	 // changes table attributes	
		tdRight.setAttribute("height",heightSetLeft);	 // changes table attributes				
		swatchDivClose = swatchDiv;	// sets global variable	
	}
	if (NS4)
	{
	}
}

// function to turn of swatches
function swatchOff()
{
	if(IE4 || IE5)
	{
		if (IE5MAC)
		{
			//swatchDivClose.style.offsetTop = "-400px";
			//swatchDivClose.style.offsetLeft = "-400px";				
		}
		else
		{
			swatchDivClose = eval(swatchDivClose);
			swatchDivClose.style.visibility = "hidden";		
			swatchDivClose.style.top = "-400px";
			swatchDivClose.style.left = "-400px";				
		}		
	}
	if (N6)
	{		
		document.getElementById(swatchDivClose).style.visibility = "hidden";
		document.getElementById(swatchDivClose).style.top = "-400px";
		document.getElementById(swatchDivClose).style.left = "-400px";
	}	
	if (NS4)
	{
	}
}
