/*
* Variable 'S' defines the speed of the accordian
* Variable 'T' defines the refresh rate of the accordian
*/
s=1;
t=10;

// Prototype Method to get the element based on ID
function $(d){
	return document.getElementById(d);
}
// set or get the current display style of the div
function dsp(d,v){
	if(v==undefined){
		return d.style.display;
	}else{
		d.style.display=v;
	}
}
// set or get the height of a div.
function sh(d,v){
	// if you are getting the height then display must be block to return the absolute height
	if(v==undefined){
		return d.offsetHeight;
	}else{
		d.style.height=v;
	}
}
//Collapse Timer is triggered as a setInterval to reduce the height of the div exponentially.
function ct(d){
	d = $(d);
	if(sh(d)>0){
		v = Math.round(sh(d)/d.s);
		v = (v<1) ? 1 :v ;
		v = (sh(d)-v);
		sh(d,v+'px');
	}else{
		sh(d,0);
		//dsp(d,'none');
		clearInterval(d.t);
	}
}
//Expand Timer is triggered as a setInterval to increase the height of the div exponentially.
function et(d){
	d = $(d);
	if(sh(d)<d.maxh){
		v = Math.round((d.maxh-sh(d))/d.s);
		v = (v<1) ? 1 :v ;
		v = (sh(d)+v);
		sh(d,v+'px');
	}else{
		sh(d,d.maxh);
		clearInterval(d.t);
	}
}
// Collapse Initializer
function cl(d){
	clearInterval(d.t);
	d.t=setInterval('ct("'+d.id+'")',t);
}
//Expand Initializer
function ex(d){
	d.style.height='0px';
	clearInterval(d.t);
	d.t=setInterval('et("'+d.id+'")',t);
}
//Accordian Initializer
function Accordion(d,s) {
	// get all the elements that have id as content
	l=$(d).getElementsByTagName('div');
	c=[];
	for(i=0;i<l.length;i++){
		h=l[i].id;
		if(h.substr(h.indexOf('-')+1,h.length)=='content'){c.push(h);}
	}
	sel=null;
	//then search through headers
	for(i=0;i<l.length;i++){
		h=l[i].id;
		if(h.substr(h.indexOf('-')+1,h.length)=='header'){
			d=$(h.substr(0,h.indexOf('-'))+'-content');
			d.style.overflow='hidden';
			d.maxh =sh(d);
			d.s=(s==undefined)? 7 : s;
			h=$(h);
			h.c=c;
			if( l[i].className == 'off' ) 
				sh(d,'0px');
			// set the onclick function for each header.
			h.onclick = function(){
				for(i=0;i<this.c.length;i++){
					cn=this.c[i];
					n=cn.substr(0,cn.indexOf('-'));
					if((n+'-header')==this.id){
						ex($(n+'-content'));
						n=$(n+'-header');
					}else{
						cl($(n+'-content'));
					}
				}
			}
		}
	}
	if(sel!=undefined){sel.onclick();}
}


function PositionStrapline() {
    var top_pos = document.getElementById("MasterFrame").clientHeight - 70;
    document.getElementById('StraplineFoot').style.top = top_pos + 'px';
}



/* Jobs Page show/hide layer */

function toggle(element) {

    if (document.getElementById(element).style.display == "none") {
        document.getElementById(element).style.display = "";
        document.getElementById('bullet'+element).src="assets/images/jobBulletDown.jpg";
    } else {
        document.getElementById(element).style.display = "none";
        document.getElementById('bullet'+element).src="assets/images/jobBullet.jpg";
    }

}


function addEvent(obj, evType, fn){ 
 if (obj.addEventListener){ 
   obj.addEventListener(evType, fn, false); 
   return true; 
 } else if (obj.attachEvent){ 
   var r = obj.attachEvent("on"+evType, fn); 
   return r; 
 } else { 
   return false; 
 } 
}

addEvent(window, 'load', PositionStrapline);

var offsetfrommouse = [5,5]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var displayduration=0; //duration in seconds image should remain visible. 0 for always. 
var defaultimageheight = 380;	// maximum image size.
var defaultimagewidth = 255;	// maximum image size. 
var timer; 

function gettrailobj(){
    if (document.getElementById)
        return document.getElementById("ImagePopup").style
} 
function gettrailobjnostyle(){
    if (document.getElementById)
        return document.getElementById("ImagePopup")
}  
function truebody(){
    return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}  
function hidetrail(){		
    gettrailobj().display= "none";	
    document.onmousemove=""	
    gettrailobj().left="-1000px"	
    clearTimeout(timer);
} 
function showtrail(imagename,title,width,height){	
    i = imagename	
    t = title	
    w = width	
    h = height	
    timer = setTimeout("show('"+i+"',t,w,h);",10);
}
function show(imagename,title,width,height){     
    var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth - offsetfrommouse[0]	
    var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight) 	
    if( (navigator.userAgent.indexOf("Konqueror")==-1  || navigator.userAgent.indexOf("Firefox")!=-1 || (navigator.userAgent.indexOf("Opera")==-1 && navigator.appVersion.indexOf("MSIE")!=-1))) {		
        document.onmousemove=followmouse;   		
        newHTML = '<img src="assets\\images\\products\\' + imagename + '" border="0">'		 		
        gettrailobjnostyle().innerHTML = newHTML;
    }
} 
function followmouse(e){ 	
    var xcoord=offsetfrommouse[0]
    var ycoord=offsetfrommouse[1]

    var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
    var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

    if (typeof e != "undefined"){
	    if (docwidth - e.pageX < defaultimagewidth + 2*offsetfrommouse[0]){
		    xcoord = e.pageX - xcoord - defaultimagewidth; // Move to the left side of the cursor
	    } else {
		    xcoord += e.pageX;
	    }
	    if (docheight - e.pageY + document.body.scrollTop < (defaultimageheight + offsetfrommouse[1])){
		    ycoord += e.pageY - Math.max(0,(offsetfrommouse[1] + defaultimageheight + e.pageY - docheight - document.body.scrollTop));
	    } else {
		    ycoord += e.pageY;
	    }

    } else if (typeof window.event != "undefined"){
	    if (docwidth - event.clientX < defaultimagewidth + 2*offsetfrommouse[0]){
		    xcoord = event.clientX + truebody().scrollLeft - xcoord - defaultimagewidth; // Move to the left side of the cursor
	    } else {
		    xcoord += truebody().scrollLeft+event.clientX
	    }
	    if (docheight - event.clientY < (defaultimageheight + 2*offsetfrommouse[1])){
		    ycoord += event.clientY + truebody().scrollTop - Math.max(0,(2*offsetfrommouse[1] + defaultimageheight + event.clientY - docheight));
	    } else {
		    ycoord += truebody().scrollTop + event.clientY;
	    }
    }
    gettrailobj().left=xcoord+"px"
    gettrailobj().top=ycoord+"px"
    gettrailobj().display="block";	
}         
