/* Greybox Redux
 * Required: http://jquery.com/
 * Written by: John Resig
 * Based on code by: 4mir Salihefendic (http://amix.dk)
 * License: LGPL (read more in LGPL.txt)
 */
var GB_DONE = false;
var ie=(document.all);
var ns=(document.layers);
var ns6=(document.getElementById && !ie);
var calculate=ns? "" : "px"
function GB_show(caption, url, height, width) {
	GB_HEIGHT = height;
	GB_WIDTH = width;
	$("#GB_window").remove();
	$("#GB_overlay").remove(); // Virendra Thursday, June 18, 2009
	$(document.body)
	.append("<div id='GB_overlay'></div><div id='GB_window'><div id='GB_font'></div>" + "<img src='images/close.gif' title='Close' id='imgClose' alt='Close'/></div>");
	$("#GB_window img").click(GB_hide);
	$(window).resize(GB_position);
	$("#GB_frame").remove();
	$("#GB_window").append("<iframe  class='GB_frame' id='GB_frame' name='GB_frame' src='"+url+"'></iframe>");
	$("#GB_font").html(caption);
	$("#GB_overlay").show();
	var frameId	=	"GB_frame";
	GB_position(frameId);
	if(GB_ANIMATION)
		$("#GB_window").slideDown("fast");
	else
		$("#GB_window").show();
}

function GB_showWithName(caption, url, height, width, frameId) {
	GB_HEIGHT = height;
	GB_WIDTH = width;
	$("#GB_window").remove();
	$("#GB_overlay").remove(); // Virendra Thursday, June 18, 2009
	$(document.body)
	.append("<div id='GB_overlay'></div><div id='GB_window'><div id='GB_font'></div>" + "<img src='images/close.gif' title='Close' id='imgClose' alt='Close'/></div>");
	$("#GB_window img").click(GB_hide);
	$(window).resize(GB_position);
	$("#" +frameId + "").remove();
	$("#GB_window").append("<iframe class='GB_frame' id='"+frameId+"' name='"+frameId+"' src='"+url+"'></iframe>");
	$("#GB_font").html(caption);
	$("#GB_overlay").show();
	GB_position(frameId);
	if(GB_ANIMATION)
		$("#GB_window").slideDown("fast");
	else
		$("#GB_window").show();
}
function GB_showInner(caption, url, height, width, frameId) {
	GB_HEIGHT = height;
	GB_WIDTH = width;
	$("#GB_window").remove();
	$("#GB_overlay").remove(); // Virendra Thursday, June 18, 2009
	$(document.body)
	.append("<div id='GB_overlay'></div><div id='GB_window'><div id='GB_font'></div>" + "<img src='../images/close.gif' title='Close' id='imgClose' alt='Close'/></div>");
	$("#GB_window img").click(GB_hide);
	$(window).resize(GB_position);
	$("#" +frameId + "").remove();
	$("#GB_window").append("<iframe class='GB_frame' id='"+frameId+"' name='"+frameId+"' src='"+url+"'></iframe>");
	$("#GB_font").html(caption);
	$("#GB_overlay").show();
	GB_position(frameId);
	if(GB_ANIMATION)
		$("#GB_window").slideDown("fast");
	else
		$("#GB_window").show();
}
function GB_hide() {
	$("#GB_window,#GB_overlay").hide();
}
function GB_position(frameId)
{
	var de = document.documentElement;
	var winw = GB_WIDTH;
	var winh = GB_HEIGHT;
	if(navigator.appName ==  "Microsoft Internet Explorer"){
		var bHeight = parseInt(document.documentElement.clientHeight)/2;
	}else
	{
		var bHeight = parseInt(window.innerHeight)/2;
	}
	var agent=navigator.userAgent.toLowerCase();
	if (ie){
		if (navigator.userAgent.indexOf("Opera")>=0) {
			documentHeight=window.innerHeight/2+window.pageYOffset-(winh/2);
		}else{
			documentHeight = (centerElement().offsetHeight)/2+centerElement().scrollTop-(winh/2);
		}
	}
	else if (ns){
		documentHeight=window.innerHeight/2+window.pageYOffset-(winh/2);
	}
	else if (ns6){
		documentHeight=self.innerHeight/2+window.pageYOffset-(winh/2);
	}
	if(documentHeight < 0)
	{
		var toppos = documentHeight + 100 + "px";
	}else
	{
		var toppos = documentHeight+calculate;
	}
	var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	 $("#GB_window").css({width:GB_WIDTH+"px",height:GB_HEIGHT+"px",
	left: ((w - GB_WIDTH)/2)+"px",top: toppos });
	$("#" + frameId + "").css("height",GB_HEIGHT-20 +"px");
	var arrayPageSizeWithScroll =	getPageSizeWithScroll();
	$("#GB_overlay").css("height",arrayPageSizeWithScroll[1] +"px");
	setTimeout("GB_position()",100);
}
function centerElement(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}
function getPageSizeWithScroll(){
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else 
	if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight;
		xWithScroll = document.body.offsetWidth;
	}
	arrayPageSizeWithScroll = new Array(xWithScroll,yWithScroll);
	return arrayPageSizeWithScroll;
}
