/* 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 GB_ANIMATION = true;
var GB_HEIGHT = 500;
var GB_WIDTH = 850;

function GB_show(url, width, height, type) {
	GB_HEIGHT = height || GB_HEIGHT;
	GB_WIDTH = width || GB_WIDTH;
	if(!GB_DONE) {
		//定义两种不同的样式
		if(!type){
			$(document.body)
				.append("<div id='GB_overlay'></div><div id='GB_window'><div id='GB_close'><a>CLOSE</a></div>"
				+ "<div id='GB_box'></div></div>");
			$("#GB_window #GB_close a").click(GB_hide);
			//$("#GB_overlay").click(GB_hide);
			$(window).resize(GB_position);
			GB_DONE = true;
		}else{
			$(document.body)
				.append("<div id='GB_overlay2'></div><div id='GB_window'><div id='GB_close2'><a>CLOSE</a></div>"
				+ "<div id='GB_box'></div></div>");
			$("#GB_window").css("border","5px #1A4963 solid");
			$("#GB_window #GB_close2 a").click(GB_hide);
			//$("#GB_overlay2").click(GB_hide);
			$(window).resize(GB_position);
			GB_DONE = true;
		}
	}

	$("#GB_frame").remove();
	$("#GB_box").append("<iframe id='GB_frame' frameborder='0' src='"+url+"'></iframe>");

	$("#GB_overlay").show();
	$("#GB_overlay2").show();

	GB_position();

	if(GB_ANIMATION)
		$("#GB_window").fadeIn("slow");
	else
		$("#GB_window").show();
	}

function GB_hide() {
	$("#GB_window,#GB_overlay,#GB_overlay2").hide();
}

function GB_position() {
	var de = document.documentElement;
	var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var h = self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;

	if(window.XMLHttpRequest){
		//非IE6
		$("#GB_window").css({
			width : GB_WIDTH +"px",
			height : GB_HEIGHT+"px", 
			left : ((w - GB_WIDTH)/2)+"px", 
			top : ((h - GB_HEIGHT)/2)+"px"
		});
		$("#GB_frame").css({
			height : GB_HEIGHT - 30 + "px"
		});
	}else{
		//IE6
		$("#GB_window").css({
			width : GB_WIDTH + "px",
			height : GB_HEIGHT + "px", 
			left : ((w - GB_WIDTH)/2) + "px", 
			top : ((h - GB_HEIGHT)/2) + document.documentElement.scrollTop+"px"
		});
		$("#GB_frame").css({
			height : GB_HEIGHT - 30 + "px",
			width : GB_WIDTH - 12 + "px"
		});
	}
}

