﻿var agt=navigator.userAgent.toLowerCase();
var scroll = "";
var screencheck = 1000;
if (agt.indexOf("ie") != -1) {scroll = 'scrolling = "yes" allowtransparency="true" frameborder="no"';}

var overlayheight = 0;

var url=document.URL;
var http = url.split("winwood-products.com")[0];
var domain = http + "winwood-products.com";

//###########################################################################################
var offsetL = 0;
var opened = 0;
var lightbox_width_correction = 0;
var lightbox_height_correction = 0;
var offsetT = 515;
var olwidth, olheight, calc_width, calc_height1, calc_height2, calc_height_result, lightbox_content, overlay;
var delay = 500;
if(agt.indexOf("ie") != -1) {delay = delay*0.7;}
var poplaroffsetL = 0;
var poplaroffsetT = 0;
var opacityval = 0;
var currentlink;

//spliturl = url.split('eng/')
//stub = spliturl[1]

//var newUrl = url.toLowerCase();

//	if (newUrl.indexOf("default.htm") != -1) {
//	   var defaulturl = url.split("default.htm")
//	   newUrl = defaulturl[0]
//	}
//if (newUrl.indexOf("timber_products") != -1 || newUrl.indexOf("marine_plywood") != -1) {
//   newUrl = newUrl.replace("timber_products","timber-products")
//   newUrl = newUrl.replace("marine_plywood","plywood/okoume-plywood")
//}
//if (url != newUrl) {
//   location.replace(newUrl)
//}

////document.write('<div id="pageurlprint">/eng/' +stub+ '</div>')


window.onresize = size_overlay;

//###########################################################################################
function loadjscssfile(filename, filetype){
   var fileref;
   if (filetype=="js"){ //if filename is a external JavaScript file
      fileref=document.createElement('script');
      fileref.setAttribute("type","text/javascript");
      fileref.setAttribute("src", filename);
   }
   else if (filetype=="css"){ //if filename is an external CSS file
      fileref=document.createElement("link");
      fileref.setAttribute("rel", "stylesheet");
      fileref.setAttribute("type", "text/css");
      fileref.setAttribute("href", filename);
      fileref.setAttribute("media", "screen");
   }
   if (typeof fileref!="undefined") {
      document.getElementsByTagName("head")[0].appendChild(fileref);}
}
var topwindow = window.top.location;
topwindow = topwindow+'';
         
// LOAD WIDE CSS ONLY IF MODERN BROWSER WITH WIDE SCREEN - CORRECT ERRORS IN LTE IE7 WITH DOCUMENT.DOCUMENTMODE, ETC
if (screen.availWidth > screencheck) {
   loadjscssfile(domain + "/winwood-wide.css","css");

   if (agt.indexOf("ie") != -1 && !document.documentMode) { // FOR IE 7 AND BELOW
      loadjscssfile(domain + "/winwood-wide-ie.css","css");
   }
   if (agt.indexOf("ie") != -1 && !window.XMLHttpRequest) { // FOR IE 6 AND BELOW
      loadjscssfile(domain + "/winwood-wide-ie6.css","css");
   }
   if (agt.indexOf("ie") != -1 && !document.compatMode) {   // FOR IE 5.5 AND BELOW
      loadjscssfile(domain + "/winwood-wide-ie5.5.css","css");
   }
}

if (self != top) {
   if (topwindow.indexOf("veneered_panels.htm") != -1 ||
   topwindow.indexOf("sculptured-panels") != -1 ||
   topwindow.indexOf("mesh-plywood.htm") != -1 ||
   topwindow.indexOf("coloured-mdf.htm") != -1 ||
   (topwindow.indexOf("edge_glued_panels") != -1 && topwindow.indexOf("worktops") == -1 )||
   topwindow.indexOf("test.htm") != -1 || topwindow.indexOf("test-scroll.htm") != -1) {
      loadjscssfile(domain + "/winwoodpopups.css","css");
   }
}
if (document.getElementById){ // SETS CSS TO SHOW ACTIVE CONTENT RELIANT UPON JAVASCRIPT & LOADS SCRIPTS
   loadjscssfile(domain + "/activedocbyid.css","css");
   if (agt.indexOf("ie") != -1 && !document.documentMode && document.getElementById("linkdetails")) { // FOR IE 7 AND BELOW
      document.getElementById("linkdetails").style.height = "20.9em";}
   if (agt.indexOf("ie") != -1 && !document.compatMode && self == top) {   // FOR IE 5.5 AND BELOW
      var ie5text = 'Microsoft has discontinued support of Internet Explorer 5.5 & earlier.<br/>';
      ie5text+= 'To offer the best facilities on this website some code used is suitable only for more modern browsers (IE6 & above)<br/><br/>';
      ie5text+= 'You may need to <a href="http://www.microsoft.com/windows/internet-explorer/" target="_blank"><b>update your browser</b></a> ';
      ie5text+= 'in order for all features and tools on this website to work correctly';
      document.write('<span style="background-color:#ffa; font-size:0.8em;  margin:35px auto -45px; width:100%">' +ie5text+ '</span>')
   }
   if (url.indexOf("poplar_plywoods") != -1) {
         loadjscssfile(domain + "/eng/timber-products/plywood/poplar-activebyid.css","css");
      if (screen.availWidth > screencheck) {
         loadjscssfile(domain + "/eng/timber-products/plywood/poplar-wide.css","css");
      }
   }
}


//###########################################################################################
// TO BE USED TO SLIDE SITEMAP DIVS WITHIN INIT
//	   var divs = container.getElementsByTagName('div');
//	   for (var i=0; i<divs.length; i++){
//		   var section = divs[i];
//		   if (section.className == "link2product"){  // HIDDEN LINKS ON SITEMAP & PRODUCT PAGE
//		      section.style.visibility = "hidden";
//         }
//      }
      
//###########################################################################################
function init(){
   if (agt.indexOf("ie") != -1 && !document.compatMode) {   // EXCLUDE IE 5.5 AND BELOW
   }
   else {
      if (agt.indexOf("ie") != -1 && !window.XMLHttpRequest && url.indexOf("veneered_panels.htm") != -1) {
         document.getElementById("venpagespacer").style.height = "269px";
         if (screen.availWidth > 1000) {
            document.getElementById("venpagespacer").style.height = "558px";
         }
      }
      var container = document.getElementById('container'), lightDiv = document.createElement('div'), overlayDiv = document.createElement('div');
      var infobox;
      if (self == top) {
         var pageurlprint=document.createElement('span');
         pageurlprint.setAttribute("id","pageurlprint");
         container.parentNode.insertBefore(pageurlprint, container);
         document.getElementById("pageurlprint").innerHTML = url;
         
//         document.write('<span id="pageurlprint">' +url+ '</span>')

         if (document.getElementById("infobox")) {
            infobox = document.getElementById("infobox");
            setOpacity("infobox",0);
   //         infobox.style.height = "273px";
            infobox.style.display = "none";
            infobox.style.overflow = "hidden";
   //         infobox.style.borderBottom = "solid 1px #ccc";
         }
      }

//###########################################################################################
	   if (document.getElementById('linkmore')) {   // PARTIALLY HIDE DESCRIPTION IF TOO LONG
	      var linkmore = document.getElementById('linkmore');
	      var linkdetails = document.getElementById('linkdetails');
         linkheight = linkdetails.clientHeight;
	      if (linkdetails.scrollHeight > linkdetails.clientHeight) {
	         linkmore.innerHTML = '... <span>click to see more of this description</span>&nbsp;<img class="downbullet" alt="" src="../../../images/down.gif" />';
            linkmore.style.display = "block";
	         linkdetails.style.height = "270px";
	         linkmore.onclick = function() {
		         linkdetails.style.height = 'auto';
               linkmore.style.display = 'none';
            };
         }
      }

//###########################################################################################
	   if (document.getElementById('footer')) {  ///   ADD EMAIL ADDRESS
	      var footer = document.getElementById('footer');
	      footer.innerHTML = '<a href="mailto:info@winwood-products.com">info@winwood-products.com</a> ' + footer.innerHTML;
      }

//###########################################################################################
      if(url.indexOf("veneercontent/") == -1 &&
         url.indexOf("sculptured-panels/thumbnails") == -1) {
	      var anchors = container.getElementsByTagName('a');
         for (var i=0; i<anchors.length; i++){
		      var anchor = anchors[i];
		   
		   
//###########################################################################################
		      if (anchor.className == "linkedpage" && screen.availWidth > screencheck){  // IFRAME POPUPS
			      anchor.onclick = function() {
                  var divheight = 480;
                  var divwidth = 857;
                  var infobox = document.getElementById("infobox");
                  if (url.indexOf("veneered_panels") != -1) {
                     divheight = 250;}
                  if (currentlink != this.href) {
                     infobox.innerHTML = '<div id="productclose" class="hiddenwindowclose">'+
                     '<a href="' +this.href+ '">See this as full page</a> :: '+
                     '<a href="#" onclick="hide(); return false">Close this box</a>'+
                     '</div>'+
                     '<iframe src="' +this.href+ '" class="infowindow" id="infopopup" name="infopopup" '+
                     'style="height:' +divheight+ 'px;width:' +divwidth+ 'px;" '+scroll+ '>'+
                     '</iframe>';
                     if (url.indexOf("mesh-plywood.htm") != -1) {
                        var meshlink = document.getElementById("meshlinkdiv")
                        var coverlinks = document.createElement('div');
                        coverlinks.setAttribute("id","coverlinks");
                        meshlink.appendChild(coverlinks);
                        var coverlinkdiv = document.getElementById("coverlinks");
                        setTimeout(function(){coverlinkdiv.parentNode.removeChild(coverlinkdiv);},delay);
                     }
                     infobox.style.height = (divheight + 30) + "px";
                     if (infobox.style.display == "none") {
                        show();
                     }
                     else {
                        setOpacity("infobox",0);
                        appear("infobox",10);
                     }
                     currentlink = this.href;
                  }
                  else if (infobox.style.display == "none") {
                     show();
                  }
                  return false;
               }
            }
//###########################################################################################
		      else if (anchor.parentNode.id == "veneerchoices"){  // IMAGE POPUPS
			      anchor.onclick=function() {
			         showdk(this.id);
                  return false;
               }
            }
//###########################################################################################
		      else if (anchor.className == "linkedimg"){  // IMAGE POPUPS
			      anchor.onclick=function() {
                  if (self != top) {
                     return false;
                  }
                  else {
                     var description;
                     description = this.title;
                     if (this.title.indexOf(":") != -1) {
                        description = description.replace(": ",":<br/><span id=\"popupsubtitle\">") + "</span>"
                     }
                     if (this.title.indexOf(" (") != -1) {
                        description = description.replace(" (","<br/>(")
                     }
                     lightDiv.setAttribute("id","lightbox_content");
                     overlayDiv.setAttribute("id","overlay");

                     container.parentNode.insertBefore(lightDiv, container);
                     container.parentNode.insertBefore(overlayDiv, container);
                     lightbox_content = document.getElementById("lightbox_content");
                     overlay = document.getElementById("overlay");
                     
                     lightbox_content.style.height = overlay.style.height = "500px";
                     setOpacity("lightbox_content",0);
                     setOpacity("overlay",6);
                     lightbox_content.style.display = "none";
                     overlay.style.display = "none";
                     lightbox_content.innerHTML = '<img id="lightimg" style="width:100%; height:300px; border:solid 1px #000;" src=' +
                     this.href +
                     ' /><br/><h2 style="border-bottom:solid 1px #ccc;height:50px;margin-top:0;padding:0;">' +
                     description+
                     '</h2><a id="hidelightbox" href="javascript:void(0)">Close this window</a>';
                     lightbox_width_correction = 200;
                     lightbox_height_correction = 120;
                     lightbox_content.style.width = "400px";
                     lightbox_content.style.height = "370px";
                     if (url.indexOf("veneer/") != -1 && !(url.indexOf("veneer/veneer") != -1 || url.indexOf("veneer/jointed") != -1)) {
                        var lightimg_s = document.getElementById("lightimg").style
                        lightbox_content.style.height = "470px";
                        lightbox_content.style.width = "300px";
                        lightbox_width_correction = 150;
                        lightbox_height_correction = 50;
                        lightimg_s.height = "400px";
                        lightimg_s.width = "300px";
                     }
                     getCumulativeOffset(this);
                     size_overlay();
                     overlay.style.display='block';
                     lightbox_content.onclick = closelightbox;
                     overlay.onclick = closelightbox;
                     lightbox_content.style.display='block';
                     appear("lightbox_content",10);
                     return false;
                  }
               };
            }
//###########################################################################################
		      else if (anchor.className == "veneerprodlink"){  // IMAGE POPUPS
			      anchor.onclick=function() {
			         var choice = this.href.replace('veneer/','');
			         choice = choice.replace(domain + '/eng/timber-products/','').replace('.htm','')
                  document.cookie = "winwood-venproduct"+"="+escape(choice)+" ;path=/";
                  top.location = domain + '/eng/timber-products/veneered_panels.htm'
                  return false;
               }
            }
//###########################################################################################
         }
         if (lightbox_content) {
         }
      }
   }
   if (url.indexOf("faqs") != -1 || url.indexOf("veneered_panels.htm") != -1 ) {
	   var spans = document.getElementById("container").getElementsByTagName('span');

      for (var i=0; i<spans.length; i++){
		   var span = spans[i];
//###########################################################################################
		    if (span.className == "question"){  // Q & A SECTIONS
			   span.onclick=function() {
			      answer = this.id.replace("question:","");
//               setOpacity(answer,0);
			      if (document.getElementById(answer).style.display == "block") {
			         document.getElementById(answer).style.display = "none";
			      }
			      else {
//                  appear(answer,10);
			         document.getElementById(answer).style.display = "block";
               }
            };
         }
      }
   }
}

//###########################################################################################
function framehiddenlinksinit() {
   var anchors = document.getElementById("content").getElementsByTagName('a');

   for (var i=0; i<anchors.length; i++){
      var anchor = anchors[i];
         anchor.onclick = function() {
          return false;
      };
   }
}

//###########################################################################################
var closestarted;
function closelightbox() {
   if (closestarted == "yes") {
      return false;
   }
   else {
      closestarted = "yes";
      fade("lightbox_content");
      function cleardivs() {
         if (lightbox_content.style.display != "none") {
		      setTimeout(cleardivs, delay/10);
         }
         else {
            lightbox_content.parentNode.removeChild(lightbox_content);
            overlay.parentNode.removeChild(overlay);
            closestarted = "";
         }
      }
      setTimeout(cleardivs, delay/10);  // Call cleardivs() for the first time
   }
}

//###########################################################################################
function hide(objid) {
   if (objid == null) {objid = "infobox";}
   if (agt.indexOf("ie") != -1 && !window.XMLHttpRequest && url.indexOf("veneered_panels.htm") != -1) {
      document.getElementById(objid).style.display = "none";      // HAD TO RESORT TO THIS BOTCH JOB TO SORT THE WAY THE FUCK-UP
      document.getElementById(objid).style.visibility = "hidden"; // CALLED IE6 PERFORMS ON THIS PAGE!!!
      setOpacity(objid,0);
      if (document.getElementById("veneer1frame").style.display == "none" &&
            document.getElementById("veneer2frame").style.display == "none" &&
            document.getElementById("inlayframe").style.display == "none" &&
            document.getElementById("match1frame").style.display == "none") {
         document.getElementById("venpagespacer").style.height = "269px";   //display = "block"
         if (screen.availWidth > 1000) {
            document.getElementById("venpagespacer").style.height = "558px";   //display = "block"
         }
      }
   }
   else {
      fade(objid);
      slideup(objid);
   }
}

//###########################################################################################
function show(objid) {
   if (objid == null) {objid = "infobox";}
   if (agt.indexOf("ie") != -1 && !window.XMLHttpRequest && url.indexOf("veneered_panels.htm") != -1) {
      document.getElementById(objid).style.display = "block";      // HAD TO RESORT TO THIS BOTCH JOB TO SORT THE WAY THE FUCK-UP
      document.getElementById(objid).style.visibility = "visible"; // CALLED IE6 PERFORMS ON THIS PAGE!!!
      setOpacity(objid,10);
      var venspacerht = document.getElementById("venpagespacer");
      if (objid == "inlayframe") {
         document.getElementById("venpagespacer").style.height = "1px";}    //display = "none"
      if (screen.availWidth > 1000) {
      }
      else {
      }
      document.getElementById("venpagespacer").style.height = "518px";    //display = "none"
      if (screen.availWidth > 1000) {
         if(objid == "veneer1frame" || objid == "match1frame") {
            document.getElementById("venpagespacer").style.height = "558px";}    //display = "none"
         else {
            document.getElementById("venpagespacer").style.height = "537px";}    //display = "none"
      }
         
   }
   else {
      appear(objid,10);
      slidedown(objid);
   }
}
//function toggle(objid) {
//   if (objid == null) objid = "infobox"
//   if (document.getElementById(objid).style.display != "block") show(objid)
//   else hide(objid)
//}

//###########################################################################################
var timerlen = 2;

var timerID = new Array();
var startTime = new Array();
var arrayobj = new Array();
var endHeight = new Array();
var moving = new Array();
var dir = new Array();

function slidedown(objname){
        if(moving[objname]) return;
        if(document.getElementById(objname).style.display == "block") return; // cannot slide down something that is already visible

        moving[objname] = true;
        dir[objname] = "down";
        startslide(objname);
}

function appear(domId,max){
	obj = document.getElementById(domId); //Get the element
//	if(opacityval != 0) return false; //Return if it is already being displayed
//	obj.style.display = ''; //Un-hide the object before its animation
	var alpha = 0; //Set the initial value of alpha to 0 (invisible)
	function a(){ //Internal function
		alpha++; //Increment alpha
		setOpacity(domId, alpha); //Set the opacity of our element to the specified alpha
		if(alpha < max) {
		   setTimeout(a, delay/10);
		}
		else {
		   setOpacity(domId, 10);
//         obj.style.display = 'block'; //
      }
		/*Till alpha is 10, keep calling the
		a() function after 100 milliseconds */
	}
	setTimeout(a, delay/10); //This is where we call the a() function for the first time
};


function slideup(objname){
        if(moving[objname]) return;
        if(document.getElementById(objname).style.display == "none") return; // cannot slide up something that is already hidden

        moving[objname] = true;
        dir[objname] = "up";
        startslide(objname);
}

function fade(domId){
	obj = document.getElementById(domId); //Get the Element
	if(opacityval > 0) return false; //Return false if the element is already hidden
	var alpha = 10; //Set the initial value of alpha
//	if(domID = "overlay") alpha = 6
	function f(){ //Internal function
		alpha--; //Decrememnt the alpha value
		setOpacity(domId, alpha); //Set the opacity of our element to the specified alpha
		if(alpha > -1){ //If alpha is still bigger than -1 then..
         setTimeout(f, delay/10); //..then call the function again after 100 milliseconds
		}
		else{ //otherwise..
         setOpacity(domId, 0);
			obj.style.display = 'none'; //..otherwise now that we cant see the element anyways, hide it
		}
	}
	setTimeout(f, delay/10); //This is where we call the f() function for the first time
//	opacityval = 0;

};

function startslide(objname){
        arrayobj[objname] = document.getElementById(objname);

        endHeight[objname] = parseInt(arrayobj[objname].style.height);
//        alert(endHeight[objname])
        startTime[objname] = (new Date()).getTime();

        if(dir[objname] == "down"){
                arrayobj[objname].style.height = "1px";
        }

        arrayobj[objname].style.display = "block";

        timerID[objname] = setInterval('slidetick(\'' + objname + '\');',timerlen);
}

function slidetick(objname){
        var elapsed = (new Date()).getTime() - startTime[objname];

        if (elapsed > delay)
                endSlide(objname)
        else {
                var d =Math.round(elapsed / delay * endHeight[objname]);
                if(dir[objname] == "up")
                        d = endHeight[objname] - d;

                arrayobj[objname].style.height = d + "px";
        }

        return;
}

function endSlide(objname){
        clearInterval(timerID[objname]);

        if(dir[objname] == "up")
                arrayobj[objname].style.display = "none";

        arrayobj[objname].style.height = endHeight[objname] + "px";

        delete(moving[objname]);
        delete(timerID[objname]);
        delete(startTime[objname]);
        delete(endHeight[objname]);
        delete(arrayobj[objname]);
        delete(dir[objname]);

        return;
}

//###########################################################################################
function setOpacity(domId, opacityval) {
	obj = document.getElementById(domId);
	obj.style.MozOpacity = opacityval;
	obj.style.opacity = opacityval/10;
	obj.style.filter = 'alpha(opacity=' + opacityval*10 + ')';
	return opacityval;
};




//###########################################################################################
function size_overlay() {
   if (agt.indexOf("ie") != -1 && !document.compatMode) {   // EXCLUDE IE 5.5 AND BELOW
   }
   else if(overlay) {
      if (document.documentElement.clientWidth || window.innerWidth) {
         if (document.documentElement.clientWidth) {
            calc_width = document.documentElement.clientWidth
            calc_height1 = document.body.clientHeight
            calc_height2 = document.documentElement.clientHeight
         }
         else {
            calc_width = window.innerWidth
            calc_height1 = document.body.clientHeight
            calc_height2 = window.innerHeight
         }
        if (calc_height2 >= calc_height1) calc_height2 += 16
        calc_height_result = Math.max(calc_height1,calc_height2)
   if (agt.indexOf("ie") != -1 && !window.XMLHttpRequest) { // EXCLUDE IE 6 AND BELOW
         }
            overlay.style.height = (calc_height_result + 30)  +"px"
         overlay.style.width = calc_width +"px"
      }
            lightbox_content.style.marginLeft = calc_width/2 - lightbox_width_correction +"px"
            lightbox_content.style.marginTop = offsetT - lightbox_height_correction +"px"
   }
}


//###########################################################################################
function iebody() {
    // Sense the difference between Strict and Quirks mode
    return (document.compatMode != "BackCompat"? document.documentElement : document.body);
}
if (iebody().clientHeight > iebody().scrollHeight) {
   overlayheight = iebody().clientHeight;
} else {
   overlayheight = iebody().scrollHeight;
}



function checkforcookie() {
   document.cookie = "winwood-cookiecheck=;path=/;";
}

var d = new Date();



//###########################################################################################
function opacity(id, opacStart, opacEnd, millisec) { 
    //speed for each frame
    var speed = Math.round(millisec / 100); 
    var timer = 0;
    if (opened == 0) {
      //determine the direction for the blending, if start and end are the same nothing happens 
       if(opacStart > opacEnd) { 
           for(i = opacStart; i >= opacEnd; i--) { 
               setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
               timer++; 
           } 
       } else if(opacStart < opacEnd) { 
           for(i = opacStart; i <= opacEnd; i++) 
               { 
               setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
               timer++; 
           } 
       } 
    }
} 

//###########################################################################################
// Changes the opacity for each browser type
function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
}

//###########################################################################################
function shiftOpacity(id, millisec) { 
    //if an element is invisible, make it visible, else make it ivisible 
    if(document.getElementById(id).style.opacity == 0) { 
        opacity(id, 0, 100, millisec); 
    } else { 
        opacity(id, 100, 0, millisec); 
    } 
}

//###########################################################################################
function blendimage(divid, imageid, imagefile, millisec) { 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 
     
    //set the current image as background 
    document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")"; 
     
    //make image transparent 
    changeOpac(0, imageid); 
     
    //make new image 
    document.getElementById(imageid).src = imagefile; 

    //fade in image 
    for(i = 0; i <= 100; i++) { 
        setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed)); 
        timer++; 
    } 
}
 
//###########################################################################################
function getCumulativeOffset(obj) {
   var correction = 0
   if(obj.parentNode.className == "colourmdfimg") {
      correction = 35
      if (obj.title.indexOf("Grey") != -1 || obj.title.indexOf ("Orange") != -1 || obj.title.indexOf ("Red") != -1 || obj.title.indexOf ("Yellow") != -1)
         correction = 198
   }
   if (obj.offsetParent) {
      offsetL = obj.offsetLeft
      offsetT = obj.offsetTop
      while (obj = obj.offsetParent) {
         offsetL += obj.offsetLeft
         offsetT += obj.offsetTop

      }
   }
   poplaroffsetL = offsetL
   poplaroffsetT = offsetT
   offsetT += -1 * correction
//alert(offsetT +", "+ calc_height_result)
   if (offsetL + 400 > calc_width) {
      offsetL = calc_width - 400;}
   if (offsetT + 380 > calc_height_result) {
      offsetT = calc_height_result - 380;}
//alert(offsetT)
if (url.indexOf("engineered-wood.htm") != -1) {offsetT = 330;}
   return [offsetL,offsetT];
}

//###########################################################################################
function test(choice){
   var m1 = document.getElementById(choice);
   if ( m1.currentStyle ) {
      alert(m1.currentStyle.height);
   } else if ( document.defaultView.getComputedStyle ){
      alert(document.defaultView.getComputedStyle(m1,'') .height);
   } else {
      return;
   }
}


//###########################################################################################
startStack=function() { };  // A stack of functions to run onload/domready

registerOnLoad = function(func) {
   var orgOnLoad = startStack;
   startStack = function () {
      orgOnLoad();
      func();
      return;
   }
}

var ranOnload=false; // Flag to determine if we've ran the starting stack already.

if (document.addEventListener) {
  // Mozilla actually has a DOM READY event.
   document.addEventListener("DOMContentLoaded", function(){if (!ranOnload) {ranOnload=true; startStack();}}, false);
}  else if (document.all && !window.opera) {
  // This is the IE style which exploits a property of the (standards defined) defer attribute
  document.write("<scr" + "ipt id='DOMReady' defer=true " + "src=//:><\/scr" + "ipt>");  
  document.getElementById("DOMReady").onreadystatechange=function(){
    if (this.readyState=="complete"&&(!ranOnload)){
      ranOnload=true;
      startStack();
    }
  }
}

var orgOnLoad=window.onload;
window.onload=function() {
   if (typeof(orgOnLoad)=='function') {
      alert(url)
      orgOnLoad();
   }
   if (!ranOnload) {
     ranOnload=true;
     startStack();
   }
}


if (self == top) {  
   registerOnLoad(init);
}
if (url.indexOf("veneered_panels.htm") != -1) {
   registerOnLoad(veneerinit);
}
else if (url.indexOf("coloured-mdf.htm") != -1) {
   registerOnLoad(colouredmdfinit);
}
else if (url.indexOf("fineline.htm") != -1) {
   registerOnLoad(finelineinit);
}
else if (url.indexOf("mesh-plywood.htm") != -1) {
   registerOnLoad(meshinit);
}
else if (url.indexOf("poplar_plywoods.htm") != -1) {
   registerOnLoad(poplarinit);
}
else if (url.indexOf("sitemap.htm") != -1 || url.indexOf("products.htm") != -1) {
   registerOnLoad(showhideinit);
}
else if (url.indexOf("sculptured-panels") != -1 && url.indexOf(".htm") == -1) {
      registerOnLoad(sculpturedinit);
   if (screen.availWidth > screencheck) {
      loadjscssfile(domain + "/eng/timber-products/sculptured-panels/sculptured-popups-wide.css","css")
      if (agt.indexOf("ie") != -1 && !document.documentMode) { // FOR IE 7 AND BELOW
         loadjscssfile(domain + "/eng/timber-products/sculptured-panels/sculptured-popups-wide-ie.css","css")
      }
      if (agt.indexOf("ie") != -1 && !document.compatMode) {   // FOR IE 5.5 AND BELOW
         loadjscssfile(domain + "/eng/timber-products/sculptured-panels/sculptured-popups-wide-ie5.5.css","css")
      }
   }
}
else if ((url.indexOf("sculptured-panels") != -1 && top.location.href.indexOf("coloured-mdf") != -1) || 
      (url.indexOf("timber-products/veneer/") != -1 && top.location.href.indexOf("veneered_panels.htm") != -1)) {
   loadjscssfile(domain + "/winwood-framehiddenlinks.css","css")
   registerOnLoad(framehiddenlinksinit);
}
