var ie4=document.all;
var ns6=document.getElementById&&!document.all;

timer2 = 5000;
intOpacity2 = 100;
var left, top;
var currentId;

var screenHeight = document.documentElement.clientHeight;
var screenWidth = document.documentElement.clientWidth;

if (window.addEventListener)
{				
	window.addEventListener("resize", magicResize, false);   
	//document.attachEvent("onmousemove", getMouseXY);	
}
else if (document.addEventListener) 
{	
    window.addEventListener("resize", magicResize, false);    
	//document.addEventListener("mousemove", getMouseXY, true);
}
else
{
	window.attachEvent("onresize", magicResize);
	//document.attachEvent("onmousemove", getMouseXY);	
}


function magicResize()
{
	screenHeight = document.documentElement.clientHeight;
	screenWidth = document.documentElement.clientWidth;
}

function loadImage(imageURL, previewIdent)
{
	document.getElementById("fullsize-image").src = imageURL;	
	//alert(previewIdent);
	fnFindBrowserStyle(document.getElementById("thumb1")).borderColor = (document.getElementById("thumb1").id == previewIdent) ? "#ff94ae" : "#c0c0c0";
	fnFindBrowserStyle(document.getElementById("thumb2")).borderColor = (document.getElementById("thumb2").id == previewIdent) ? "#ff94ae" : "#c0c0c0";
	fnFindBrowserStyle(document.getElementById("thumb3")).borderColor = (document.getElementById("thumb3").id == previewIdent) ? "#ff94ae" : "#c0c0c0";
	//alert(fnFindBrowserStyle(document.getElementById("thumb3")).borderColor);
}


function viewProductImages(id)
{
		productWindow = window.open("view_product.php?id="+id, 'productWindow', "status=0, resizable=0, toolbar=no,location=no, scrollbars=no, width=750, height=700, top=10, screenX=0, left=10, screenY=0");
}

	
		
//sortPng();

var DDSPEED = 5;
var DDTIMER = 15;

// main function to handle the mouse events //
function ddMenu(id,d){
  var h = document.getElementById('ddheader'+id);
  var c = document.getElementById('ddcontent'+id);
  c.style.display = "block";
  clearInterval(c.timer);
  if(d == 1){
    clearTimeout(h.timer);
    if(c.maxh && c.maxh <= c.offsetHeight){ return}
    else if(!c.maxh){
      c.style.display = 'block';
      c.style.height = 'auto';
      c.maxh = c.offsetHeight;
      c.style.height = '0px';
    }
    c.timer = setInterval(function(){ddSlide(c,1)},DDTIMER);
  }else{
    h.timer = setTimeout(function(){ddCollapse(c)},50);
  }
}

// collapse the menu //
function ddCollapse(c){
  c.timer = setInterval(function(){ddSlide(c,-1)},DDTIMER);
}

// cancel the collapse if a user rolls over the dropdown //
function cancelHide(id){
  var h = document.getElementById('ddheader'+id);
  var c = document.getElementById('ddcontent'+id);
  clearTimeout(h.timer);
  clearInterval(c.timer);
  if(c.offsetHeight < c.maxh){
    c.timer = setInterval(function(){ddSlide(c,1)},DDTIMER);
  }
}

// incrementally expand/contract the dropdown and change the opacity //
function ddSlide(c,d){
  var currh = c.offsetHeight;
  var dist;
  if(d == 1){
    dist = (Math.round((c.maxh - currh) / DDSPEED));
  }else{
    dist = (Math.round(currh / DDSPEED));
  }
  if(dist <= 1 && d == 1){
    dist = 1;	
  }
  c.style.height = currh + (dist * d) + 'px';
  if (!ie4)
  {
	c.style.opacity = currh / c.maxh;
	c.style.filter = 'alpha(opacity=' + (currh * 100 / c.maxh) + ')';
  }
  
  //alert(currh);
  
  if((currh <= 2 && d != 1) || (currh > (c.maxh - 2) && d == 1)){
    if (currh==2) c.style.display = "none";
    clearInterval(c.timer);
  }
}



function xmlInit()
{
  xmlhttp=false;
  
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try 
 {
   xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } 
 catch (e) 
 {
  try 
  {
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } 
  catch (E) 
  {
    xmlhttp = false;
  }
 }
@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined')
	  xmlhttp = new XMLHttpRequest();
}


function AJAXRequest(Filename, CallbackFunction)
{	
  xmlInit();
  xmlhttp.open("GET", Filename, true);
  xmlhttp.onreadystatechange=CallbackFunction;
  xmlhttp.send(null)
}


function cb_DisplayCalendar()
{
	if (xmlhttp.readyState==4) // Ensure it only attempts to populate details on success.
	{		
	  Results = xmlhttp.responseText;
	  
	  document.getElementById("calendar-of-events").innerHTML = Results;
	}
}


function getMouseXY(e)
{		
/*
		if (ie4) 
		{
	    	left = event.clientX + document.documentElement.scrollLeft;
		    top = event.clientY + document.documentElement.scrollTop;
	  	} 
		else 
		{
	    	left = e.pageX;
		    top = e.pageY;
	  	}	 
		
		if (left < 0) left = 0;
	  	if (top < 0) top = 0; 
		
		//if (top > screenHeight-160) top = screenHeight-160;
		//if (left > screenWidth-200) left = screenWidth-200;
		
		fnFindBrowserStyle(document.getElementById("popupCalendar")).left = (left+1) + "px";
		fnFindBrowserStyle(document.getElementById("popupCalendar")).top = (top-15) + "px";	
	*/			
}


function keepEvent()
{
  changeOpacity(100, "popupCalendar");
  intOpacity = 100;
  
  clearTimeout(timer2);
}

function popupEvent(id, message, event)
{	
	if (currentId != id)
	{
		getMouseXY(event);
		currentId = id;
	}	
	
	document.getElementById("popupCalendar").innerHTML = "<a href=\"javascript:fnRemovePopup();void(0);\"><img src=\"images/close.gif\" alt=\"Close\" id=\"close\" /></a>"+message;
	fnFindBrowserStyle(document.getElementById("popupCalendar")).display = "block";
}


function popupDownEvent()
{
	timer2=setTimeout('fadePopup()', 1000);
}


function fadePopup()
{
  
  intOpacity2-=10;   
  
  changeOpacity(intOpacity2, "popupCalendar");
  
  if (intOpacity2 <= 0)
    fnRemovePopup();    
  else
    timer2=setTimeout('fadePopup()', 50);
}

function changeOpacity(newOpacity, elementId)
{
    //if (ie4)
        //fnFindBrowserStyle(document.getElementById(elementId)).filter = "progid:DXImageTransform.Microsoft.Alpha(opacity="+newOpacity+");"
    //else
    //{
        fnFindBrowserStyle(document.getElementById(elementId)).KhtmlOpacity = (newOpacity/100);
    	fnFindBrowserStyle(document.getElementById(elementId)).MozOpacity = (newOpacity/100);
    //}  
}

function fnRemovePopup()
{
  fnFindBrowserStyle(document.getElementById("popupCalendar")).display="none";
  changeOpacity(100, "popupCalendar");
  intOpacity2 = 100;
}


function sortPng()
{
 if (document.all && /MSIE (5\.5|6)/.test(navigator.userAgent) && document.styleSheets && document.styleSheets[0] && document.styleSheets[0].addRule)
 {  
  document.styleSheets[0].addRule('img', 'behavior: url(sitespecific/iepngfix.htc)');
  document.styleSheets[0].addRule('div', 'behavior: url(sitespecific/iepngfix.htc)');
 }
} 

function highlightMenu(menuId)
{  document.getElementById(menuId).className="menOver";	 }

function unHighlightMenu(menuId)
{  document.getElementById(menuId).className="";  }

function fnFindBrowserStyle(objIdent)
{ return ((ie4||ns6) ? objIdent.style : objIdent); }
