/*
Global scripts used on www.prestera.biz
Christofer Sandin, Republic Factory AB <www.republic.se>
*/


// attach eventListener to DOM element
function attachEventListener(target, eventType, functionRef, capture) 
{ 
  if (typeof target.addEventListener != "undefined") { 
    target.addEventListener(eventType, functionRef, capture); 
  } else if (typeof target.attachEvent != "undefined") { 
    target.attachEvent("on" + eventType, functionRef); 
  } else { 
    eventType = "on" + eventType; 
    if (typeof target[eventType] == "function") { 
      var oldListener = target[eventType]; 
      target[eventType] = function() 
      { 
      oldListener(); 
      return functionRef(); 
      }; 
    } else { 
      target[eventType] = functionRef; 
    } 
  } 
}

// add multiple events "onload"  
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}


function showTooltip( dv, n ) {
	var f = new getObj( dv );
	f.style.display = "inline";
	if ( n > 1 )
		f.style.top = ((n-1) * 35)+5-((n-1)*1)+'px';
	else
		f.style.top = '5px';

	//alert(f.style.top);
}
function hideTooltip( dv ) {
	var f = new getObj( dv );
	f.style.display = "none";
}

function getObj(name)
{
  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
}


// show/hide tooltips on product page
/*
function showTooltipOne() {
  document.getElementById("product_one_tooltip").style.display = "inline";
}
function hideTooltipOne() {
  document.getElementById("product_one_tooltip").style.display = "none";
}
function showTooltipTwo() {
  document.getElementById("product_two_tooltip").style.display = "inline";
}
function hideTooltipTwo() {
  document.getElementById("product_two_tooltip").style.display = "none";
}

*/



// functions to run on page load
function init() { 
  styleOnHover("sub_nav_one", "hover_one");
  styleOnHover("sub_nav_two", "hover_two");
  styleOnHover("sub_nav_three", "hover_three", "sub_nav_two", "hover_three");
/*
  if(document.getElementById("product_one_image")) {
    var prod_one = document.getElementById("product_one_image");
    attachEventListener(prod_one, "mouseover", showTooltipOne, false);
    attachEventListener(prod_one, "mouseout", hideTooltipOne, false);
    var prod_two = document.getElementById("product_two_image");
    attachEventListener(prod_two, "mouseover", showTooltipTwo, false);
    attachEventListener(prod_two, "mouseout", hideTooltipTwo, false);
  }*/
}

// pre-load images  
function preloadImages() {
  var imgNames = ['images/sub_nav_one.gif', 'images/sub_nav_two.gif', 'images/sub_nav_three.gif'];
  var imgObjects = [];
  for(var j = 0; j < imgNames.length; j++) {
    imgObjects[j] = new Image();
    imgObjects[j].src = imgNames[j];
  }
}

addLoadEvent(preloadImages);
addLoadEvent(init);
