/*
DezinerFolio.com Simple Accordians.

Author  : G.S.Navin Raj Kumar
Website : http://dezinerfolio.com

*/

/*
* The Variable names have been compressed to achive a higher level of compression.
*/

// 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) {
		if(dsp(d)!= 'none'&& dsp(d) != ''){
			//opera.postError(d.offsetHeight);
			return d.offsetHeight - 1;
		}
		viz = d.style.visibility;
		d.style.visibility = 'hidden';
		o = dsp(d);
		dsp(d,'block');
		r = parseInt(d.offsetHeight);
		dsp(d,o);
		d.style.visibility = viz;
		return r;
	}else{
		d.style.height = v;
	}
}

function getHeight(el) {
	if (el.parent) {
		return el.offsetHeight + getHeight(el.parent);
	}
	el.offsetHeight;
}
/*
* Variable 'S' defines the speed of the accordian
* Variable 'T' defines the refresh rate of the accordian
*/
s=7;
t=100;

//Collapse Timer is triggered as a setInterval to reduce the height of the div exponentially.
function ct(d){
	d = $(d);
	//alert(sh(d));
//	if(sh(d) > 25){
//		v = Math.round(sh(d)/d.s);
//		v = (v<1) ? 1 :v ;
//		v = (sh(d)-v);
//		sh(d,v+'px');
		//d.style.opacity = (v/d.maxh);
		//d.style.filter= 'alpha(opacity='+(v*100/d.maxh)+');';
//	}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');
//		d.style.opacity = (v/d.maxh);
//		d.style.filter= 'alpha(opacity='+(v*100/d.maxh)+');';
//	}else{
		sh(d,d.maxh);
		clearInterval(d.t);
//	}
}

// Collapse Initializer
function cl(d){
	if(dsp(d)=='block'){
		clearInterval(d.t);
		d.t=setInterval('ct("'+d.id+'")',t);
	}
}

//Expand Initializer
function ex(d){
	if(dsp(d)=='none'){
		dsp(d,'block');
		d.style.height='0px';
		clearInterval(d.t);
		d.t=setInterval('et("'+d.id+'")',t);
	}
}

// Removes Classname from the given div.
function cc(n,v){
	s=n.className.split(/\s+/);
	for(p=0;p<s.length;p++){
		if(s[p]==v+n.tc){
			s.splice(p,1);
			n.className=s.join(' ');
			break;
		}
	}
}
//Accordian Initializer
function Accordian(d,s,tc){
	// 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.display='none';
			d.style.overflow='hidden';
			d.maxh =sh(d);
			d.s=(s==undefined)? 7 : s;
			h=$(h);
			h.tc=tc;
			h.c=c;
			// 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');
						cc(n,'__');
						n.className=n.className+' '+n.tc;
					}else{
						cl($(n+'-content'));
						cc($(n+'-header'),'');
					}
				}
			}
			if(h.className.match(/selected+/)!=undefined){ sel=h;}
		}
	}
	if(sel!=undefined){sel.onclick();}
}

function hideTip() {
	tip.style.display = 'none';
}

function showTip(app) {
	var str = "<table class='shortcuts-table' width='400px' cellspacing='1px'><tr><td class='kheader' colspan='2'>" + app + "</td></tr>";
	for (i = 0; i < keys.length; i++) {
		str += "<tr><td class='key'>" + keys[i][0] + "</td><td>" + keys[i][1] + "</td></tr>";
	}

	tip.innerHTML = str + "<tr><td class='kfooter' colspan='2'>Download the programm to view all keyboard shortcuts.</td></tr></table>";
	tip.style.left = xMousePos + 5;
	tip.style.top = yMousePos + 10;
//	tip.style.opacity = 0;
//	tip.style.filter= 'alpha(opacity=0);';
	tip.style.display = 'block';
//	tipInterval = setInterval('showTipEx()', 10);
}

function showTipEx() {
	if(tip.style.opacity <= 255){
		tip.style.opacity += 20;
		tip.style.filter= 'alpha(opacity='+tip.style.opacity+');';
	}else{
		tip.style.opacity = 255;
		tip.style.filter= 'alpha(opacity='+tip.style.opacity+');';
		clearInterval(tipInterval);
	}
}

function updateTipPos() {
	tip.style.left = xMousePos + 5;
	tip.style.top = yMousePos + 10;
}
keys = [[],[]];
tipInterval = 0;
xMousePos = 0; // Horizontal position of the mouse on the screen
yMousePos = 0; // Vertical position of the mouse on the screen
xMousePosMax = 0; // Width of the page
yMousePosMax = 0; // Height of the page

function captureMousePosition(e) {
    if (document.layers) {
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    } else if (document.all) {
        xMousePos = window.event.x+document.body.scrollLeft;
        yMousePos = window.event.y+document.body.scrollTop;
        xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
        yMousePosMax = document.body.clientHeight+document.body.scrollTop;
    } else if (document.getElementById) {
        xMousePos = e.pageX;
        yMousePos = e.pageY;
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    }
}
