$(document).ready(function(){
	$.browser.msie6 = $.browser.msie && /MSIE 6\.0/i.test(window.navigator.userAgent) && !/MSIE 7\.0/i.test(window.navigator.userAgent);
	
	// Menu
	$("ul.menu li.sm a").click(function(e){
		__displayMenu(this);
		return false;
	});
	$("ul.menu li.sm ul a").unbind("click");
	
	// Lightbox
	lb_init();
	
	// Video
	$("div.box2").hide();
	$("div.verbatim").hide();
	$("div.verbatim").css({ "position":"absolute", "margin":"-356px 0 0 580px" });
	$("ul#tab a").click(function(e){
		if($(this).attr("href") != "#"){
			$("div.verbatim").hide();
			$("div.box2").hide();
			$("ul#tab a").removeClass("current");
			//window.setTimeout("__readyHandler('" + $(this).attr("class") + "');", 0);
			$("div#" + $(this).attr("class")).show();
			$(this).addClass("current");
			return false;
		}
	});
	$("ul#tab a").mousedown(function(e){
		return false;
	});
	$("div.btn a").click(function(e){
		var obj = window.event ? window.event.srcElement : e ? e.target : null;
		if(obj.nodeName != "A"){ obj = obj.parentNode; }
		obj = obj.parentNode.parentNode;
		if($("#" + $(obj).attr("id") + " div.verbatim").css("display") != "none"){
			$("#" + $(obj).attr("id") + " div.verbatim").fadeOut();
		}else{		
			$("#" + $(obj).attr("id") + " div.verbatim").fadeIn();
		}
		return false;
	});
	$("div.verbatim p.close a").click(function(e){
		var obj = window.event ? window.event.srcElement : e ? e.target : null;
		if(obj.nodeName != "P"){ obj = obj.parentNode; }
		obj = obj.parentNode;
		$(obj).fadeOut();
		return false;
	});
	var id = "object1";
	/*var href = window.location.href.substring(window.location.href.lastIndexOf("#") + 1, window.location.href.length);
	if(/(object)([0-9]{1,})/.test(href)){
		id = href;
	}*/
	$("div#" + id).show();
	$("a." + id).addClass("current");
	
	// Resolution
	if((screen.width <= 1024) || (screen.height <= 768)){
		var html = $("#right").html();
		if(html != null && html != ""){
			$("#right").remove();
			$("#content").prepend('<div id="right">' + html + '</div>');
			$("#right").css({
				"float":"none",
				"padding-top":"20px"
			});
		}
		$("#supportingText").css({
			"float":"none"
		});
	}
	
	// External link
	/*$("a[rel*='external']").click(function(){
		this.target = "_blank";
	});*/
});

// ________________________________________________________
// Video ready handler
function __readyHandler(id){
	$("div#" + id).show();
	// Set scrollbar to saved position - need to use timeout with 0 to prevent browser scroll to target of hash
	var scrollX = window.pageXOffset || document.documentElement && document.documentElement.scrollLeft || document.body.scrollLeft || 0;
	var scrollY = window.pageYOffset || document.documentElement && document.documentElement.scrollTop || document.body.scrollTop || 0;
	window.scrollTo(scrollX, scrollY);
}

// ________________________________________________________
// Display menu
function __displayMenu(e){
	var id = $(e).attr("id");
	if($("ul.menu ul." + id).css("display") == "none"){
		$("ul.menu ul." + id).slideDown("fast");
		for(var i = 1; i <= 4; i++){
			if(id != ("s" + i)){
				$("ul.menu ul.s" + i).slideUp("fast");
			}
		}
	}else{
		$("ul.menu ul." + id).slideUp("fast");
	}
}

// ________________________________________________________
// Get page size
function __getPageSize(){
	var xScroll, yScroll;
	if(window.innerHeight && window.scrollMaxY){	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	}else if(document.body.scrollHeight > document.body.offsetHeight){
		// All but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	}else{
		// Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if(self.innerHeight){
		// All except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		}else{
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	}else if(document.documentElement && document.documentElement.clientHeight){
		// Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	}else if(document.body){
		// Other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}
	// For small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	}else{ 
		pageHeight = yScroll;
	}
	// For small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	}else{
		pageWidth = windowWidth;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
};

// ________________________________________________________
// Get page scroll
function __getPageScroll(){
	var xScroll, yScroll;
	if(self.pageYOffset){
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	}else if(document.documentElement && document.documentElement.scrollTop){
		// Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;

	}else if(document.body){
		// All other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}
	arrayPageScroll = new Array(xScroll,yScroll);
	return arrayPageScroll;
};