var timeout	= 500;
var closetimer	= 0;
var ddmenuitem	= 0;

// open hidden layer
function mopen(id) {	
  // cancel close timer
  mcancelclosetime();

  // close old layer
  mclose();

  // get new layer and show it
  ddmenuitem = document.getElementById('m' + id);
  if (ddmenuitem) {

    ddmenuitem.style.display = 'block';
  }
}

// close showed layer
function mclose() {
  if (ddmenuitem) ddmenuitem.style.display = 'none';
}

// go close timer
function mclosetime() {
  closetimer = window.setTimeout(mclose, timeout);
}

// cancel close timer
function mcancelclosetime() {
  if (closetimer) {
    window.clearTimeout(closetimer);
	closetimer = null;
  }
}

// close layer when click-out
document.onclick = mclose; 

/**
 * teclan slideshow functionality.
 * Any changes to this file will not be supported by teclan.
 *
 * @copyright teclan 2009
 */

var fadebgcolor = '#fff';
var fadearray=new Array() //array to cache fadeshow instances
var fadeclear=new Array() //array to cache corresponding clearinterval pointers
var dom=(document.getElementById) //modern dom browsers
var iebrowser=document.all
function fadeshow(theimages, fadewidth, fadeheight, borderwidth, delay, pause, displayorder, bgcolor) {
fadebgcolor = bgcolor;
this.pausecheck=pause
this.mouseovercheck=0
this.delay=delay
this.degree=10 //initial opacity degree (10%)
this.curimageindex=0
this.nextimageindex=1
fadearray[fadearray.length]=this
this.slideshowid=fadearray.length-1
this.canvasbase="canvas"+this.slideshowid
this.curcanvas=this.canvasbase+"_0"
if (typeof displayorder!="undefined")
theimages.sort(function() {return 0.5 - Math.random();}) //thanks to Mike (aka Mwinter) :)
this.theimages=theimages
this.imageborder=parseInt(borderwidth)
this.postimages=new Array() //preload images
for (p=0;p<theimages.length;p++){
this.postimages[p]=new Image()
this.postimages[p].src=theimages[p][0]
}
var fadewidth=fadewidth+this.imageborder*2
var fadeheight=fadeheight+this.imageborder*2
if (iebrowser&&dom||dom) //if IE5+ or modern browsers (ie: Firefox)
document.write('<div id="master'+this.slideshowid+'" style="position:relative;width:'+fadewidth+'px;height:'+fadeheight+'px;overflow:hidden;"><div id="'+this.canvasbase+'_0" style="position:absolute;width:'+fadewidth+'px;height:'+fadeheight+'px;top:0;left:0;filter:progid:DXImageTransform.Microsoft.alpha(opacity=10);opacity:0.1;-moz-opacity:0.1;-khtml-opacity:0.1;background-color:'+fadebgcolor+'"></div><div id="'+this.canvasbase+'_1" style="position:absolute;width:'+fadewidth+'px;height:'+fadeheight+'px;top:0;left:0;filter:progid:DXImageTransform.Microsoft.alpha(opacity=10);opacity:0.1;-moz-opacity:0.1;-khtml-opacity:0.1;background-color:'+fadebgcolor+'"></div></div>')
else
document.write('<div><img name="defaultslide'+this.slideshowid+'" src="'+this.postimages[0].src+'"></div>')
if (iebrowser&&dom||dom) //if IE5+ or modern browsers such as Firefox
this.startit()
else{
this.curimageindex++
setInterval("fadearray["+this.slideshowid+"].rotateimage()", this.delay)
}
}
function fadepic(obj){
if (obj.degree<100){
obj.degree+=10
if (obj.tempobj.filters&&obj.tempobj.filters[0]){
if (typeof obj.tempobj.filters[0].opacity=="number") //if IE6+
obj.tempobj.filters[0].opacity=obj.degree
else //else if IE5.5-
obj.tempobj.style.filter="alpha(opacity="+obj.degree+")"
}
else if (obj.tempobj.style.MozOpacity)
obj.tempobj.style.MozOpacity=obj.degree/101
else if (obj.tempobj.style.KhtmlOpacity)
obj.tempobj.style.KhtmlOpacity=obj.degree/100
else if (obj.tempobj.style.opacity&&!obj.tempobj.filters)
obj.tempobj.style.opacity=obj.degree/101
}
else{
clearInterval(fadeclear[obj.slideshowid])
obj.nextcanvas=(obj.curcanvas==obj.canvasbase+"_0")? obj.canvasbase+"_0" : obj.canvasbase+"_1"
obj.tempobj=iebrowser? iebrowser[obj.nextcanvas] : document.getElementById(obj.nextcanvas)
obj.populateslide(obj.tempobj, obj.nextimageindex)
obj.nextimageindex=(obj.nextimageindex<obj.postimages.length-1)? obj.nextimageindex+1 : 0
setTimeout("fadearray["+obj.slideshowid+"].rotateimage()", obj.delay)
}
}
fadeshow.prototype.populateslide=function(picobj, picindex){
var slideHTML=""
if (this.theimages[picindex][1]!="") //if associated link exists for image
slideHTML='<a href="'+this.theimages[picindex][1]+'" target="'+this.theimages[picindex][2]+'">'
slideHTML+='<img src="'+this.postimages[picindex].src+'" border="'+this.imageborder+'px">'
if (this.theimages[picindex][1]!="") //if associated link exists for image
slideHTML+='</a>'
picobj.innerHTML=slideHTML
}
fadeshow.prototype.rotateimage=function(){
if (this.pausecheck==1) //if pause onMouseover enabled, cache object
var cacheobj=this
if (this.mouseovercheck==1)
setTimeout(function(){cacheobj.rotateimage()}, 100)
else if (iebrowser&&dom||dom){
this.resetit()
var crossobj=this.tempobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas)
crossobj.style.zIndex++
fadeclear[this.slideshowid]=setInterval("fadepic(fadearray["+this.slideshowid+"])",50)
this.curcanvas=(this.curcanvas==this.canvasbase+"_0")? this.canvasbase+"_1" : this.canvasbase+"_0"
}
else{
var ns4imgobj=document.images['defaultslide'+this.slideshowid]
ns4imgobj.src=this.postimages[this.curimageindex].src
}
this.curimageindex=(this.curimageindex<this.postimages.length-1)? this.curimageindex+1 : 0
}
fadeshow.prototype.resetit=function(){
this.degree=10
var crossobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas)
if (crossobj.filters&&crossobj.filters[0]){
if (typeof crossobj.filters[0].opacity=="number") //if IE6+
crossobj.filters(0).opacity=this.degree
else //else if IE5.5-
crossobj.style.filter="alpha(opacity="+this.degree+")"
}
else if (crossobj.style.MozOpacity)
crossobj.style.MozOpacity=this.degree/101
else if (crossobj.style.KhtmlOpacity)
crossobj.style.KhtmlOpacity=this.degree/100
else if (crossobj.style.opacity&&!crossobj.filters)
crossobj.style.opacity=this.degree/101
}
fadeshow.prototype.startit=function(){
var crossobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas)
this.populateslide(crossobj, this.curimageindex)
if (this.pausecheck==1){ //IF SLIDESHOW SHOULD PAUSE ONMOUSEOVER
var cacheobj=this
var crossobjcontainer=iebrowser? iebrowser["master"+this.slideshowid] : document.getElementById("master"+this.slideshowid)
crossobjcontainer.onmouseover=function(){cacheobj.mouseovercheck=1}
crossobjcontainer.onmouseout=function(){cacheobj.mouseovercheck=0}
}
this.rotateimage()
}

/**
 * Toggles the current tab in display.
 */
function toggleTab(id) {
  if (!id) id = 1;
  var tabtitle = document.getElementById("tab-title-bar");
  if (tabtitle) {
    var links = tabtitle.getElementsByTagName("a");
    for (var i = 0; i < links.length; i++) {
      if (links[i].name && links[i].name != ('tab' + id)) {
        var content = document.getElementById("tabcontent" + (i+1));
        if (content) {
          content.style.display = "none";
	      links[i].className = "";
        }
      }
      else {
        links[i].className = "selected";
      }
    }
    var tbcont = document.getElementById("tabcontent" + id);
    if (tbcont) tbcont.style.display = "block";
  }
}

/**
 * Displays the first tab once the page has loaded.
 */
function initTabs() { toggleTab(1); }
if (window.attachEvent) { window.attachEvent("onload", initTabs); } 
else { window.addEventListener("load", initTabs, false); }

/**
 * teclan Drop Down Menu functionality.
 * Any changes to this file will not be supported by teclan.
 *
 * @copyright teclan 2009
 */

var timeout	= 500;
var closeTimer = 0;
var menuParent = 0;
var menuItem = 0;
 
var $m = function(id) {
  return document.getElementById(id);
};

// open hidden layer
function tcOpen(id) {	
  // cancel close timer
  tcCancelCloseTime();

  // close old layer
  tcClose();

  // get new layer and show it
  menuParent = $m('main-link' + id);
  menuItem = $m('tc' + id);
  menuItem.style.display = 'block';
}

// close showed layer
function tcClose() {
  if (menuItem) menuItem.style.display = 'none';
  if (menuParent) {
    menuParent.className = '';
  }
}

// go close timer
function tcCloseTime() {
  closeTimer = window.setTimeout(tcClose, timeout);
}

// cancel close timer
function tcCancelCloseTime() {
  if (closeTimer) {
    window.clearTimeout(closeTimer);
	closeTimer = null;
  }
  if (menuParent) {
    menuParent.className = 'sel';
  }
}

// close layer when click-out
document.onclick = tcClose; 

/***************************************************************/
/**************** Image swapping functionality *****************/
/***************************************************************/
function swapImgwithId(orgId,newImg) {
  var mimg = $tb(orgId);
  if (mimg) {
    mimg.src = newImg;
  }
}



/**
 * teclan slideshow functionality.
 * Any changes to this file will not be supported by teclan.
 *
 * @copyright teclan 2009
 */

var fadebgcolor = '#fff';
var fadearray=new Array() //array to cache fadeshow instances
var fadeclear=new Array() //array to cache corresponding clearinterval pointers
var dom=(document.getElementById) //modern dom browsers
var iebrowser=document.all
function fadeshow(theimages, fadewidth, fadeheight, borderwidth, delay, pause, displayorder, bgcolor) {
fadebgcolor = bgcolor;
this.pausecheck=pause
this.mouseovercheck=0
this.delay=delay
this.degree=10 //initial opacity degree (10%)
this.curimageindex=0
this.nextimageindex=1
fadearray[fadearray.length]=this
this.slideshowid=fadearray.length-1
this.canvasbase="canvas"+this.slideshowid
this.curcanvas=this.canvasbase+"_0"
if (typeof displayorder!="undefined")
theimages.sort(function() {return 0.5 - Math.random();}) //thanks to Mike (aka Mwinter) :)
this.theimages=theimages
this.imageborder=parseInt(borderwidth)
this.postimages=new Array() //preload images
for (p=0;p<theimages.length;p++){
this.postimages[p]=new Image()
this.postimages[p].src=theimages[p][0]
}
var fadewidth=fadewidth+this.imageborder*2
var fadeheight=fadeheight+this.imageborder*2
if (iebrowser&&dom||dom) //if IE5+ or modern browsers (ie: Firefox)
document.write('<div id="master'+this.slideshowid+'" style="position:relative;width:'+fadewidth+'px;height:'+fadeheight+'px;overflow:hidden;"><div id="'+this.canvasbase+'_0" style="position:absolute;width:'+fadewidth+'px;height:'+fadeheight+'px;top:0;left:0;filter:progid:DXImageTransform.Microsoft.alpha(opacity=10);opacity:0.1;-moz-opacity:0.1;-khtml-opacity:0.1;background-color:'+fadebgcolor+'"></div><div id="'+this.canvasbase+'_1" style="position:absolute;width:'+fadewidth+'px;height:'+fadeheight+'px;top:0;left:0;filter:progid:DXImageTransform.Microsoft.alpha(opacity=10);opacity:0.1;-moz-opacity:0.1;-khtml-opacity:0.1;background-color:'+fadebgcolor+'"></div></div>')
else
document.write('<div><img name="defaultslide'+this.slideshowid+'" src="'+this.postimages[0].src+'"></div>')
if (iebrowser&&dom||dom) //if IE5+ or modern browsers such as Firefox
this.startit()
else{
this.curimageindex++
setInterval("fadearray["+this.slideshowid+"].rotateimage()", this.delay)
}
}
function fadepic(obj){
if (obj.degree<100){
obj.degree+=10
if (obj.tempobj.filters&&obj.tempobj.filters[0]){
if (typeof obj.tempobj.filters[0].opacity=="number") //if IE6+
obj.tempobj.filters[0].opacity=obj.degree
else //else if IE5.5-
obj.tempobj.style.filter="alpha(opacity="+obj.degree+")"
}
else if (obj.tempobj.style.MozOpacity)
obj.tempobj.style.MozOpacity=obj.degree/101
else if (obj.tempobj.style.KhtmlOpacity)
obj.tempobj.style.KhtmlOpacity=obj.degree/100
else if (obj.tempobj.style.opacity&&!obj.tempobj.filters)
obj.tempobj.style.opacity=obj.degree/101
}
else{
clearInterval(fadeclear[obj.slideshowid])
obj.nextcanvas=(obj.curcanvas==obj.canvasbase+"_0")? obj.canvasbase+"_0" : obj.canvasbase+"_1"
obj.tempobj=iebrowser? iebrowser[obj.nextcanvas] : document.getElementById(obj.nextcanvas)
obj.populateslide(obj.tempobj, obj.nextimageindex)
obj.nextimageindex=(obj.nextimageindex<obj.postimages.length-1)? obj.nextimageindex+1 : 0
setTimeout("fadearray["+obj.slideshowid+"].rotateimage()", obj.delay)
}
}
fadeshow.prototype.populateslide=function(picobj, picindex){
var slideHTML=""
if (this.theimages[picindex][1]!="") //if associated link exists for image
slideHTML='<a href="'+this.theimages[picindex][1]+'" target="'+this.theimages[picindex][2]+'">'
slideHTML+='<img src="'+this.postimages[picindex].src+'" border="'+this.imageborder+'px">'
if (this.theimages[picindex][1]!="") //if associated link exists for image
slideHTML+='</a>'
picobj.innerHTML=slideHTML
}
fadeshow.prototype.rotateimage=function(){
if (this.pausecheck==1) //if pause onMouseover enabled, cache object
var cacheobj=this
if (this.mouseovercheck==1)
setTimeout(function(){cacheobj.rotateimage()}, 100)
else if (iebrowser&&dom||dom){
this.resetit()
var crossobj=this.tempobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas)
crossobj.style.zIndex++
fadeclear[this.slideshowid]=setInterval("fadepic(fadearray["+this.slideshowid+"])",50)
this.curcanvas=(this.curcanvas==this.canvasbase+"_0")? this.canvasbase+"_1" : this.canvasbase+"_0"
}
else{
var ns4imgobj=document.images['defaultslide'+this.slideshowid]
ns4imgobj.src=this.postimages[this.curimageindex].src
}
this.curimageindex=(this.curimageindex<this.postimages.length-1)? this.curimageindex+1 : 0
}
fadeshow.prototype.resetit=function(){
this.degree=10
var crossobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas)
if (crossobj.filters&&crossobj.filters[0]){
if (typeof crossobj.filters[0].opacity=="number") //if IE6+
crossobj.filters(0).opacity=this.degree
else //else if IE5.5-
crossobj.style.filter="alpha(opacity="+this.degree+")"
}
else if (crossobj.style.MozOpacity)
crossobj.style.MozOpacity=this.degree/101
else if (crossobj.style.KhtmlOpacity)
crossobj.style.KhtmlOpacity=this.degree/100
else if (crossobj.style.opacity&&!crossobj.filters)
crossobj.style.opacity=this.degree/101
}
fadeshow.prototype.startit=function(){
var crossobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas)
this.populateslide(crossobj, this.curimageindex)
if (this.pausecheck==1){ //IF SLIDESHOW SHOULD PAUSE ONMOUSEOVER
var cacheobj=this
var crossobjcontainer=iebrowser? iebrowser["master"+this.slideshowid] : document.getElementById("master"+this.slideshowid)
crossobjcontainer.onmouseover=function(){cacheobj.mouseovercheck=1}
crossobjcontainer.onmouseout=function(){cacheobj.mouseovercheck=0}
}
this.rotateimage()
}


/**
 * Toggles the current tab in display.
 */
function toggleTab(id) {
  if (!id) id = 1;
  var tabtitle = document.getElementById("tab-title-bar");
  if (tabtitle) {
    var links = tabtitle.getElementsByTagName("a");
    for (var i = 0; i < links.length; i++) {
      if (links[i].name && links[i].name != ('tab' + id)) {
        var content = document.getElementById("tabcontent" + (i+1));
        if (content) {
          content.style.display = "none";
	      links[i].className = "";
        }
      }
      else {
        links[i].className = "selected";
      }
    }
    var tbcont = document.getElementById("tabcontent" + id);
    if (tbcont) tbcont.style.display = "block";
  }
}

/**
 * Displays the first tab once the page has loaded.
 */
function initTabs() { toggleTab(1); }
if (window.attachEvent) { window.attachEvent("onload", initTabs); } 
else { window.addEventListener("load", initTabs, false); }


/**
 * teclan Drop Down Menu functionality.
 * Any changes to this file will not be supported by teclan.
 *
 * @copyright teclan 2009
 */

var timeout	= 500;
var closeTimer = 0;
var menuParent = 0;
var menuItem = 0;
 
var $m = function(id) {
  return document.getElementById(id);
};

// open hidden layer
function tcOpen(id) {	
  // cancel close timer
  tcCancelCloseTime();

  // close old layer
  tcClose();

  // get new layer and show it
  menuParent = $m('main-link' + id);
  menuItem = $m('tc' + id);
  menuItem.style.display = 'block';
}

// close showed layer
function tcClose() {
  if (menuItem) menuItem.style.display = 'none';
  if (menuParent) {
    menuParent.className = '';
  }
}

// go close timer
function tcCloseTime() {
  closeTimer = window.setTimeout(tcClose, timeout);
}

// cancel close timer
function tcCancelCloseTime() {
  if (closeTimer) {
    window.clearTimeout(closeTimer);
	closeTimer = null;
  }
  if (menuParent) {
    menuParent.className = 'sel';
  }
}

// close layer when click-out
document.onclick = tcClose; 


/*** TECLAN CODE ***/
/**
 * teclan Plugin functionality library.
 *
 * @version 1.0.0
 * @date 21/09/09
 * @author Lewis A MacKenzie
 * @copyright teclan 2009
 */

 
/***************************************************************/
/*********************** Common Functions **********************/
/***************************************************************/
/**
 * Shortcut for document.getElmementById()
 */
var $tb = function(id) {
  return document.getElementById(id);
};

/**
 * Returns all elements of type 'nodeType' with class 'className'.
 */
var $$tb = function(nodeType, className) {
  var ret = new Array();
  var arr = document.getElementsByTagName(nodeType.toUpperCase());
  for (var i = 0; i < arr.length; i++) {
    if (arr[i].className) {
	  if (arr[i].className.split(" ").contains(className)) {
	    ret.push(arr[i]);
	  }
	}
  }
  return ret;
};

Array.prototype.contains = function (element) {
  for (var i = 0; i < this.length; i++) {
    if (this[i] == element) {
      return true;
    }
  }
  return false;
};

/**
 * Checks if on the home page.
 */
function isHomePage() {
  var loc = window.location.toString();
  return loc.indexOf("acatalog") == -1;
}

/**
 * Checks for IE
 */
function isIE() {
  return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
}


/***************************************************************/
/***************** Tab Switching Functionality *****************/
/***************************************************************/
function toggleTab(id) {
  if (!id) id = 1;
  var tabtitle = $tb("tab-title-bar");
  if (tabtitle) {
    var links = tabtitle.getElementsByTagName("a");
    for (var i = 0; i < links.length; i++) {
      if (links[i].name && links[i].name != ('tab' + id)) {
        var content = $tb("tabcontent" + (i+1));
        if (content) {
          content.style.display = "none";
	      links[i].className = "";
        }
      }
      else {
        links[i].className = "selected";
      }
    }
    var tbcont = $tb("tabcontent" + id);
    if (tbcont) tbcont.style.display = "block";
  }
}

function initTabs() { toggleTab(1); }
if (window.attachEvent) { window.attachEvent("onload", initTabs); } 
else { window.addEventListener("load", initTabs, false); }

function SwitchTab(index) {
  var titles = $tb('tab-titles');
  if (titles) {
    var titleLinks = titles.getElementsByTagName("A");
    for (var i = 0; i < titleLinks.length; i++) {
	  //set the title class
	  titleLinks[i].className = (i == index ? "sel" : "");
	  titleLinks[i].blur();
	  var tabContent = $tb('Section' + i);
	  if (tabContent) {
	    tabContent.className = (i == index ? "section-tab-content block" : "section-tab-content");
	  }
	}
  }
}

function SwitchTabTopBottom(index) {
  //if (tabId === undefined) {
	var titlesTop = $tb('tab-titlesTop' );
	var titlesBottom = $tb('tab-titlesBottom');

  if (titlesTop) {
    var titleLinksTop = titlesTop.getElementsByTagName("A");
    for (var i = 0; i < titleLinksTop.length; i++) {
	  //set the title class
	  titleLinksTop[i].className = (i == index ? "sel" : "");
	  titleLinksTop[i].blur();
	  //set the content style
	  var tabContent = $tb('Section' + i);
	  if (tabContent) {
	    tabContent.className = (i == index ? "section-tab-content block" : "section-tab-content");
	  }
	}
  }
    if (titlesBottom) {
	var titleLinksBottom = titlesBottom.getElementsByTagName("A");
    for (var i = 0; i < titleLinksBottom.length; i++) {
	  //set the title class
	  titleLinksBottom[i].className = (i == index ? "sel" : "");
	  titleLinksBottom[i].blur();
	  //set the content style
	  var tabContent = $tb('Section' + i);
	  if (tabContent) {
	    tabContent.className = (i == index ? "section-tab-content block" : "section-tab-content");
	  }
	}
  }
}

/***************************************************************/
/*************** Collapsible Cart Functionality ****************/
/***************************************************************/
function collapseCart(emptyLine) {
  var cart = $tb('collapsible-cart');
  if (!cart) return;
  
  if (cart.style.display && cart.style.display == "block") {
    cart.style.display = "none";
  }
  else {
    cart.innerHTML = getMiniCart(emptyLine);
	cart.innerHTML += '<div>' + $tb('cart-links').innerHTML + '</div>';
	cart.style.display = "block";
  }
}


/***************************************************************/
/******** Fully selectable section link functionality **********/
/***************************************************************/
function initClickableSections() {
  var sections = $$tb('DIV', 'tec-section');
  for (var i = 0; i < sections.length; i++) {
    stripWhitespace(sections[i]);
	
	sections[i].onmouseover = function() {
	  this.className = "tec-section ts-hov";
	};
	sections[i].onmouseout = function() {
	  this.className = "tec-section";
	};
	
	var link = searchForLink(sections[i]);
	if (link != null) {
	  sections[i].setAttribute("rel", link);
	  sections[i].onclick = function() {
	    this.className = "tec-section ts-hov";
	    window.location = this.getAttribute("rel");
	  };
	}
  }
}

/**
 * Removes excess whitespace from a node
 */
var notWhitespace = /\S/;
function stripWhitespace(node) {
  for (var i = 0; i < node.childNodes.length; i++) {
    var childNode = node.childNodes[i];
    if ((childNode.nodeType == 3) && (!notWhitespace.test(childNode.nodeValue))) {
      node.removeChild(node.childNodes[i]);
      i--;
    }
  }
}

/**
 * Searches a node for a link element and returns the href value if found.
 */
function searchForLink(node) {
  var links = node.getElementsByTagName('A');
  if (links.length > 0) {
    return links[0].href;
  }
  return null;
}

if (window.attachEvent) { 
  window.attachEvent("onload", initClickableSections); 
} 
else {  
  window.addEventListener("load", initClickableSections, false); 
}


/***************************************************************/
/**************** Image swapping functionality *****************/
/***************************************************************/
function swapImg(newImg) {
  var mimg = $tb('main-img');
  if (mimg) {
    mimg.src = newImg;
  }
}

/***************************************************************/
/**** Image swapping functionality for Multi-product images****/
/***************************************************************/
function swapImgByID(newImg,imgID) {
  var mimg = $tb(imgID);
  if (mimg) {
    mimg.src = newImg;
  }
}



/***************************************************************/
/************************ Drop Down Menu ***********************/
/***************************************************************/
var timeout	= 500;
var closeTimer = 0;
var menuParent = 0;
var menuItem = 0;

function tcOpen(id) {	
  tcCancelCloseTime();
  tcClose();
  menuParent = $tb('main-link' + id);
  menuItem = $tb('tc' + id);
  menuItem.style.display = 'block';
  
  //code here to calculate left positioning
  
}

function tcClose() {
  if (menuItem) menuItem.style.display = 'none';
  if (menuParent) {
    menuParent.className = '';
  }
}

function tcCloseTime() {
  closeTimer = window.setTimeout(tcClose, timeout);
}

function tcCancelCloseTime() {
  if (closeTimer) {
    window.clearTimeout(closeTimer);
	closeTimer = null;
  }
  if (menuParent) {
    menuParent.className = 'sel';
  }
}

document.onclick = tcClose; 

/***************************************************************/
/******************* Mega Menu V2 ******************************/
/***************************************************************/
// open hidden layer
function tcmmv2Open(id) {	
  // cancel close timer
  tcCancelCloseTime();
  // close old layer
  tcClose();

  // get new layer and show it
  menuParent = $tb('main-link' + id);
  menuItem = $tb('tc' + id);
  menuDiv = $tb('tc-menu-container');
 
  menuItem.style.display = 'block';
  //reposition 
  //get the menu div right position
  var menuPosOnPage = findLeftPos(menuDiv);
  var itemPosOnPage = findLeftPos(menuParent);
  var menuWidth = menuDiv.offsetWidth;
  
  if (menuWidth < ((itemPosOnPage-menuPosOnPage) + menuItem.offsetWidth))  {
   // off the page so change
   menuItem.style.left = -1 * (((itemPosOnPage-menuPosOnPage) + menuItem.offsetWidth) - menuWidth) + "px";
  //alert("Off the page");
}
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
	do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	return [curleft,curtop];
}
}

function findLeftPos(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
	do {
			curleft += obj.offsetLeft;
		} while (obj = obj.offsetParent);
	return curleft;
}
}
function findRightPos(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
	do {
			curleft += obj.offsetLeft;
		} while (obj = obj.offsetParent);
	return curleft;
}
}

/***************************************************************/
/**************************** Mini Cart ************************/
/***************************************************************/
function getMiniCart(){

var tableOpen="<table width='100%'>";
var itemLine="<tr><td valign='top'>VAR:QUANTITYx </td><td><a href='VAR:LINK'>VAR:TITLE...</a></td><td align='right' valign='top'>VAR:PRICE</td></tr>"
var shippingLine="<tr><td colspan='2'>Shipping</td><td align='right'>VAR:SHIPPING</td></tr>"
var vatLine="<tr><td colspan='2'>VAT</td><td align='right'>VAR:VAT</td></tr>"
var discountLine="<tr><td colspan='2'>Discounts</td><td align='right'>VAR:DISCOUNT</td></tr>"
var surchargeLine="<tr><td colspan='2'>Surcharges</td><td align='right'>VAR:SURCHARGE</td></tr>"
var totalLine="</table><table width='100%'><tr><td><b>Total</b></td><td align='right'><b>VAR:TOTAL</b></td></tr>"
var tableClose="</table>"
var emptyLine="No items in cart.";

var cookie=getCartItem(4);

if (!cookie){
	return emptyLine;
	}
var re=new Array();
var match=new Array();
var total=0;
var str;
re[1]=/cur=([^&]*)&!/g;
re[2]=/&!(.*)/g;
re[3]=/ss=(.*)cur=/i;
re[4]=/tx=(.*)sh=/i;
re[5]=/sh=(.*)ss=/i;
for (i=1;i<re.length;i++){
	match[i]=re[i].exec(cookie);
	match[i]=match[i][1];
	}
lines=match[2].split("&!");
store=new Array();
re[0]=/^(\d*)x/;
re[1]=/x([^>]*)>/;
re[2]=/>([^>]*)>/;
re[3]=/>([^>]*)$/;
str=tableOpen;
for (i=0;i<lines.length;i++){
	for (j=0;j<re.length-2;j++){
		detail=lines[i].match(re[j]);
		store[j]=detail[1];
		}
	str+=itemLine.replace("VAR:QUANTITY",store[0]).replace("VAR:LINK",match[3]+"?PRODREF="+store[1]+"&NOLOGIN=1").replace("VAR:TITLE",store[2]).replace("VAR:PRICE",match[1]+((store[3]*1).toFixed(2)));
	total+=(store[3]*1);
	}
if (match[5] > 0){
	str+=shippingLine.replace("VAR:SHIPPING",match[1]+(match[5]/100).toFixed(2));
	total=total+=(match[5]/100);
	}
if (match[4] > 0){
	str+=vatLine.replace("VAR:VAT",match[1]+(match[4]/100).toFixed(2));
	total=total+=(match[4]/100);
	}
gTotal=getCartItem(1);
var r=/&#(\d*);/gi;
var m=new Array();
var f=new Array();
while((m = r.exec(gTotal))!=null){
	f[f.length]=m[1];
	}
for (i=0;i<f.length;i++){
	gTotal=gTotal.replace("&#"+f[i]+";","");
	}
total=total.toFixed(2);
gTotal=(gTotal/100).toFixed(2);
if (total>gTotal){
	str=str+=discountLine.replace("VAR:DISCOUNT","-"+match[1]+(total-gTotal).toFixed(2));
	}
else if (total<gTotal){
	str=str+=surchargeLine.replace("VAR:SURCHARGE",match[1]+(gTotal-total).toFixed(2));
	}
str+=totalLine.replace("VAR:TOTAL",match[1]+(gTotal));
str+=tableClose;
return str;
}


/***************************************************************/
/**************************** Height Fix ***********************/
/***************************************************************/
function heightFix() {
  var toFix = $$tb('DIV', 'fh');
  var theHighest = 0;
  for (var i = 0; i < toFix.length; i++) {
    if (toFix[i].offsetHeight > theHighest) theHighest = toFix[i].offsetHeight;
  }
  for (var i = 0; i < toFix.length; i++) {
    toFix[i].style.height = theHighest + "px";
  }
}

if (window.attachEvent) { 
  window.attachEvent("onload", heightFix); 
} 
else {  
  window.addEventListener("load", heightFix, false); 
}

function searchResultsHeightFix() {
  var toFix = $$tb('DIV', 'teclan-search-result');
  var theHighest = 0;
  for (var i = 0; i < toFix.length; i++) {
    if (toFix[i].offsetHeight > theHighest) theHighest = toFix[i].offsetHeight;
  }
  for (var i = 0; i < toFix.length; i++) {
    toFix[i].style.height = theHighest + "px";
  }
}

/***************************************************************/
/**************************** SLIDE SHOW ***********************/
/***************************************************************/

/**
 * teclan slideshow functionality.
 * Any changes to this file will not be supported by teclan.
 *
 * @copyright teclan 2009
 */

var fadebgcolor = '#fff';
var fadearray=new Array() //array to cache fadeshow instances
var fadeclear=new Array() //array to cache corresponding clearinterval pointers
var dom=(document.getElementById) //modern dom browsers
var iebrowser=document.all
function fadeshow(theimages, fadewidth, fadeheight, borderwidth, delay, pause, displayorder, bgcolor) {
fadebgcolor = bgcolor;
this.pausecheck=pause
this.mouseovercheck=0
this.delay=delay
this.degree=10 //initial opacity degree (10%)
this.curimageindex=0
this.nextimageindex=1
fadearray[fadearray.length]=this
this.slideshowid=fadearray.length-1
this.canvasbase="canvas"+this.slideshowid
this.curcanvas=this.canvasbase+"_0"
if (typeof displayorder!="undefined")
theimages.sort(function() {return 0.5 - Math.random();}) //thanks to Mike (aka Mwinter) :)
this.theimages=theimages
this.imageborder=parseInt(borderwidth)
this.postimages=new Array() //preload images
for (p=0;p<theimages.length;p++){
this.postimages[p]=new Image()
this.postimages[p].src=theimages[p][0]
}
var fadewidth=fadewidth+this.imageborder*2
var fadeheight=fadeheight+this.imageborder*2
if (iebrowser&&dom||dom) //if IE5+ or modern browsers (ie: Firefox)
document.write('<div id="master'+this.slideshowid+'" style="position:relative;width:'+fadewidth+'px;height:'+fadeheight+'px;overflow:hidden;"><div id="'+this.canvasbase+'_0" style="position:absolute;width:'+fadewidth+'px;height:'+fadeheight+'px;top:0;left:0;filter:progid:DXImageTransform.Microsoft.alpha(opacity=10);opacity:0.1;-moz-opacity:0.1;-khtml-opacity:0.1;background-color:'+fadebgcolor+'"></div><div id="'+this.canvasbase+'_1" style="position:absolute;width:'+fadewidth+'px;height:'+fadeheight+'px;top:0;left:0;filter:progid:DXImageTransform.Microsoft.alpha(opacity=10);opacity:0.1;-moz-opacity:0.1;-khtml-opacity:0.1;background-color:'+fadebgcolor+'"></div></div>')
else
document.write('<div><img name="defaultslide'+this.slideshowid+'" src="'+this.postimages[0].src+'"></div>')
if (iebrowser&&dom||dom) //if IE5+ or modern browsers such as Firefox
this.startit()
else{
this.curimageindex++
setInterval("fadearray["+this.slideshowid+"].rotateimage()", this.delay)
}
}
function fadepic(obj){
if (obj.degree<100){
obj.degree+=10
if (obj.tempobj.filters&&obj.tempobj.filters[0]){
if (typeof obj.tempobj.filters[0].opacity=="number") //if IE6+
obj.tempobj.filters[0].opacity=obj.degree
else //else if IE5.5-
obj.tempobj.style.filter="alpha(opacity="+obj.degree+")"
}
else if (obj.tempobj.style.MozOpacity)
obj.tempobj.style.MozOpacity=obj.degree/101
else if (obj.tempobj.style.KhtmlOpacity)
obj.tempobj.style.KhtmlOpacity=obj.degree/100
else if (obj.tempobj.style.opacity&&!obj.tempobj.filters)
obj.tempobj.style.opacity=obj.degree/101
}
else{
clearInterval(fadeclear[obj.slideshowid])
obj.nextcanvas=(obj.curcanvas==obj.canvasbase+"_0")? obj.canvasbase+"_0" : obj.canvasbase+"_1"
obj.tempobj=iebrowser? iebrowser[obj.nextcanvas] : document.getElementById(obj.nextcanvas)
obj.populateslide(obj.tempobj, obj.nextimageindex)
obj.nextimageindex=(obj.nextimageindex<obj.postimages.length-1)? obj.nextimageindex+1 : 0
setTimeout("fadearray["+obj.slideshowid+"].rotateimage()", obj.delay)
}
}
fadeshow.prototype.populateslide=function(picobj, picindex){
var slideHTML=""
if (this.theimages[picindex][1]!="") //if associated link exists for image
slideHTML='<a href="'+this.theimages[picindex][1]+'" target="'+this.theimages[picindex][2]+'">'
slideHTML+='<img src="'+this.postimages[picindex].src+'" border="'+this.imageborder+'px">'
if (this.theimages[picindex][1]!="") //if associated link exists for image
slideHTML+='</a>'
picobj.innerHTML=slideHTML
}
fadeshow.prototype.rotateimage=function(){
if (this.pausecheck==1) //if pause onMouseover enabled, cache object
var cacheobj=this
if (this.mouseovercheck==1)
setTimeout(function(){cacheobj.rotateimage()}, 100)
else if (iebrowser&&dom||dom){
this.resetit()
var crossobj=this.tempobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas)
crossobj.style.zIndex++
fadeclear[this.slideshowid]=setInterval("fadepic(fadearray["+this.slideshowid+"])",50)
this.curcanvas=(this.curcanvas==this.canvasbase+"_0")? this.canvasbase+"_1" : this.canvasbase+"_0"
}
else{
var ns4imgobj=document.images['defaultslide'+this.slideshowid]
ns4imgobj.src=this.postimages[this.curimageindex].src
}
this.curimageindex=(this.curimageindex<this.postimages.length-1)? this.curimageindex+1 : 0
}
fadeshow.prototype.resetit=function(){
this.degree=10
var crossobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas)
if (crossobj.filters&&crossobj.filters[0]){
if (typeof crossobj.filters[0].opacity=="number") //if IE6+
crossobj.filters(0).opacity=this.degree
else //else if IE5.5-
crossobj.style.filter="alpha(opacity="+this.degree+")"
}
else if (crossobj.style.MozOpacity)
crossobj.style.MozOpacity=this.degree/101
else if (crossobj.style.KhtmlOpacity)
crossobj.style.KhtmlOpacity=this.degree/100
else if (crossobj.style.opacity&&!crossobj.filters)
crossobj.style.opacity=this.degree/101
}
fadeshow.prototype.startit=function(){
var crossobj=iebrowser? iebrowser[this.curcanvas] : document.getElementById(this.curcanvas)
this.populateslide(crossobj, this.curimageindex)
if (this.pausecheck==1){ //IF SLIDESHOW SHOULD PAUSE ONMOUSEOVER
var cacheobj=this
var crossobjcontainer=iebrowser? iebrowser["master"+this.slideshowid] : document.getElementById("master"+this.slideshowid)
crossobjcontainer.onmouseover=function(){cacheobj.mouseovercheck=1}
crossobjcontainer.onmouseout=function(){cacheobj.mouseovercheck=0}
}
this.rotateimage()
}

/***************************************************************/
/**************************** TABS ***********************/
/***************************************************************/

/**
 * Toggles the current tab in display.
 */
function toggleTab(id) {
  if (!id) id = 1;
  var tabtitle = document.getElementById("tab-title-bar");
  if (tabtitle) {
    var links = tabtitle.getElementsByTagName("a");
    for (var i = 0; i < links.length; i++) {
      if (links[i].name && links[i].name != ('tab' + id)) {
        var content = document.getElementById("tabcontent" + (i+1));
        if (content) {
          content.style.display = "none";
	      links[i].className = "";
        }
      }
      else {
        links[i].className = "selected";
      }
    }
    var tbcont = document.getElementById("tabcontent" + id);
    if (tbcont) tbcont.style.display = "block";
  }
}

/**
 * Displays the first tab once the page has loaded.
 */
function initTabs() { toggleTab(1); }
if (window.attachEvent) { window.attachEvent("onload", initTabs); } 
else { window.addEventListener("load", initTabs, false); }


/***************************************************************/
/**************************** TCM ***********************/
/***************************************************************/

/**
 * teclan Drop Down Menu functionality.
 * Any changes to this file will not be supported by teclan.
 *
 * @copyright teclan 2009
 */

var timeout	= 500;
var closeTimer = 0;
var menuParent = 0;
var menuItem = 0;
 
var $m = function(id) {
  return document.getElementById(id);
};

// open hidden layer
function tcOpen(id) {	
  // cancel close timer
  tcCancelCloseTime();

  // close old layer
  tcClose();

  // get new layer and show it
  menuParent = $m('main-link' + id);
  menuItem = $m('tc' + id);
  menuItem.style.display = 'block';
}

// close showed layer
function tcClose() {
  if (menuItem) menuItem.style.display = 'none';
  if (menuParent) {
    menuParent.className = '';
  }
}

// go close timer
function tcCloseTime() {
  closeTimer = window.setTimeout(tcClose, timeout);
}

// cancel close timer
function tcCancelCloseTime() {
  if (closeTimer) {
    window.clearTimeout(closeTimer);
	closeTimer = null;
  }
  if (menuParent) {
    menuParent.className = 'sel';
  }
}

// close layer when click-out
document.onclick = tcClose; 
