﻿/*Call Example: 
Open: 
1、opendivs(title,url[,width,height,top,clickclose:boolean])
2、opendivx(url[,width,height,top,clickclose:boolean])	no title no border
Close: closediv()
if the document is iframe Please Use parent.opendivs() & parent.closediv()	*/

var opendivs = function(title,url){
	var opendivw = opendivs.arguments[2];
	var opendivh = opendivs.arguments[3];
	var opendivt = opendivs.arguments[4];
	var opendivc = opendivs.arguments[5];
	if(cint(opendivw)<1) opendivw = 720;
	if(cint(opendivh)<1) opendivh = 420;
	if(cint(opendivt)<1) opendivt = 76;
	if(title=="") title="Xinyour.com"
	
	opendivt+=document.documentElement.scrollTop;
	//make opendiv html model
	var opendiv_ = "<div class='opendiv'></div><div class='odc'><div class='odcop'><div class='title'>"+title+"</div><div class='close' title='点击关闭'>关闭</div></div></div>";
	var zindex=$("div.opendiv:last").css("z-index");
	$("body").append(opendiv_);
	if (typeof(zindex)!="undefined")
	{
		$("div.opendiv:last").css("z-index",zindex+5);
		$("div.odc:last").css("z-index",zindex+6);
	}
	var opendiv = $("div.opendiv:last");
	var openid = $("div.opendiv").index(opendiv);
	opendiv
		.show()
		.animate({opacity:"0.4"},0)
		.attr("id","opendiv" + openid)
		.css("height",$(document).height()+"px")	//browser
		.append("<iframe class='lap' width='100%' height='"+$(document).height()+"' frameborder='0' scrolling='no'></iframe>")
		.next("div.odc")
		.css({"width": opendivw+"px","height": opendivh+"px","margin-left": "-"+opendivw/2+"px","top": opendivt+"px","overflow":"hidden"})
		.append("<iframe width='100%' height='100%' frameborder='0' scrolling='auto' id='opiframe"+ openid +"' name='opiframe"+ openid +"' src='"+url+"'></iframe>");
		$("div.close").click(function(){
			opendiv.next("div").remove().end().remove();
		})
	//if(opendivc) opendiv.click(function(){ $(this).next("div.odc").children().children("div.close").click() })
}

var closediv = function(){
	$("div.close:last").click();
}

var opendivx = function(url){
	var opendivw = opendivx.arguments[1];
	var opendivh = opendivx.arguments[2];
	var opendivt = opendivx.arguments[3];
	var opendivc = opendivx.arguments[4];
	if(cint(opendivw)<1) opendivw = 720;
	if(cint(opendivh)<1) opendivh = 420;
	if(cint(opendivt)<1) opendivt = 76;
	
	opendivt+=document.documentElement.scrollTop;
	//make opendiv html model
	var opendiv_ = "<div class='opendiv'></div><div class='odc2'><div class='close hide'></div></div>";
	var zindex=$("div.opendiv:last").css("z-index");
	$("body").append(opendiv_);
	if (typeof(zindex)!="undefined")
	{
		$("div.opendiv:last").css("z-index",zindex+5);
		$("div.odc2:last").css("z-index",zindex+7);
	}
	var opendiv = $("div.opendiv:last");
	var openid = $("div.opendiv").index(opendiv);
	opendiv
		.show()
		.animate({opacity:"0.4"},0)
		.attr("id","opendiv" + openid)
		.css("height",$(document).height()+"px")	//browser
		.append("<iframe class='lap' width='100%' height='"+$(document).height()+"' frameborder='0' scrolling='no'></iframe>")
		.next("div.odc2")
		.css({"width": opendivw+"px","height": opendivh+"px","margin-left": "-"+opendivw/2+"px","top": opendivt+"px"})
		.append("<iframe width='100%' height='100%' frameborder='0' scrolling='auto' id='opiframe"+ openid +"' name='opiframe"+ openid +"' src='"+url+"'></iframe>");
		$("div.close").click(function(){
			opendiv.next("div").remove().end().remove();
		})
		//alert($("#opiframe"+openid).contents().find("div").length)
	//if(opendivc) opendiv.dblclick(function(){ $(this).next("div.odc2").children("div.close").click() })
}

function cint(intstr){
	var intstr_ = parseInt(intstr);
	if(isNaN(intstr_)) intstr_ = 0;
	return intstr_;
}

