// get the working width of the browser window
function screenWidth() {
  var myWidth = 0
  if( typeof( window.innerWidth ) == 'number' ) {
	//Non-IE
	myWidth = window.innerWidth;
  } else if( document.documentElement && ( document.documentElement.clientWidth ) ) {
	//IE 6+ in 'standards compliant mode'
	myWidth = document.documentElement.clientWidth;
  } else if( document.body && ( document.body.clientWidth ) ) {
	//IE 4 compatible
	myWidth = document.body.clientWidth;
  }
	return myWidth;
}

// get the working height of the browser window
function screenHeight() {
	var myHeight = 0
	if( typeof( window.innerHeight ) == 'number' ) {
		//Non-IE
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientHeight ) ) {
		//IE 4 compatible
		myHeight = document.body.clientHeight;
	}
	return myHeight;
}

// get the y scroll position of the browser window
function getScrollX() {
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
	   //DOM compliant
	   scrOfY = document.body.scrollTop;
	   scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	return scrOfX;
}

// get the y scroll position of the browser window
function getScrollY() {
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
	   //DOM compliant
	   scrOfY = document.body.scrollTop;
	   scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	return scrOfY;
}

// return object
function getItem(id) {
	var itm = false;
	if(document.getElementById)
		itm = document.getElementById(id);
	else if(document.all)
		itm = document.all[id];
	else if(document.layers)
		itm = document.layers[id];
	return itm;
}

// determine an object's absolute X co-ordinate
function findPosX(obj) {
	var curleft = 0;
	if(obj.offsetParent)
		while(1) {
		  curleft += obj.offsetLeft;
		  if(!obj.offsetParent)
			break;
		  obj = obj.offsetParent;
		}
	else if(obj.x)
		curleft += obj.x;
	return curleft;
}

// determine an object's absolute Y co-ordinate
function findPosY(obj) {
	var curtop = 0;
	if(obj.offsetParent)
		while(1) {
		  curtop += obj.offsetTop;
		  if(!obj.offsetParent)
			break;
		  obj = obj.offsetParent;
		}
	else if(obj.y)
		curtop += obj.y;
	return curtop;
}

// toggle objects
function toggleObj(itm) {
	var obj = getItem(itm);
	// ie fix
	if (itm == 'overlay') {
		$(obj).css({'filter' : 'alpha(opacity=70)'});
	}
	if (obj.style.display == 'none') {
		$(obj).fadeIn("slow");
		if (itm == 'overlay') {
			obj = getItem('overlay');
			var h1 = screenHeight();
			var h2 = document.getElementById('body').clientHeight;
			var h4 = document.getElementById('body').clientWidth;
			if (h1 > h2) {
				var h3 = h1;
			} else {
				var h3 = h2;
			}
			obj.style.width = h4 + getScrollX() + 'px';
			obj.style.height = h3 + getScrollY() + 'px';
		}
		obj.style.left = ((screenWidth() / 2) - (obj.offsetWidth / 2)) + getScrollX() + 'px';
		obj.style.top = ((screenHeight() / 2) - (obj.offsetHeight / 2)) + getScrollY() + 'px';
		objlength = obj.style.top.length;
		if (obj.style.top.substring(0,objlength - 2) < 0) {
			obj.style.top = '0px';
		}
	} else {
		$(obj).fadeOut("fast");
	}
}

// get video page
function getPage(current_page, target_page) {
	var obj = getItem(current_page);
	obj.style.display = 'none';
	toggleObj(target_page);
}

/*
 * Tooltip script 
 * powered by jQuery (http://www.jquery.com)
 * 
 * written by Alen Grakalic (http://cssglobe.com)
 * 
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 *
 */
 


this.tooltip = function(){	
	/* CONFIG */		
		xOffset = 10;
		yOffset = 20;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$("a.tooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";									  
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$("a.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};



// starting the script on page load
$(document).ready(function(){
	tooltip();
});