/**
 * ��ѧ���� -- JQ ����
 * Copyright (c) 2009 Jun(qq1270989)
 * http://www.savelearn.com/
 * http://bbs.savelearn.com/
 * admin@savelearn.com
 * ���������������������Ѳ��������� IE8 FF3.5 CHROM2.0 SAFARI4.0
 * ʹ��˵��:
 * $("#ceshi1").slwin({clickid:"showlist",type:"form",but1:"�ύ",but2:"�ر�",afterfun:aa,title:"ע��",isbj:false,isanimation:false});
 * 
 * ���÷������
 *
 * clickid       �����İ�ťID
 * type	         ���� form����erro
 * but1	         ��ť1������
 * but2          ��ť2������ 
 * afterfun      ���ť�󴥷����¼�.
 * title         �����ı�ͷ
 * width         �����Ŀ�(��̫����)
 * height        �����ĸ�(��̫����)
 * isbj          true|false �Ƿ����ñ�����.
 * isanimation   true|false �Ƿ����ö���Ч��.
 *
 */
/*--------------------------------------------------------------------------------------------------*/
$.fn.slwin = function(myobject) {
var title = "&nbsp;";
var type  = "erro";
var widthdiv = "400px";
var heightdiv ="250px";
var butname  = "确定";
var but2name = "关闭";
var functionname = "";
var showid = "";
var isbj = false;
var isanimation = true;

//showid,title,type,functionname,butname,but2name,widthdiv,heightdiv
objectlist = myobject;

if (typeof(objectlist)=="undefined") {

}else{
	if (typeof(objectlist["clickid"])!="undefined") {
		showid = objectlist["clickid"];
	}
	if (typeof(objectlist["type"])!="undefined") {
		type = objectlist["type"];
	}
	if (typeof(objectlist["height"])!="undefined") {
		heightdiv = objectlist["height"];
	}
	if (typeof(objectlist["width"])!="undefined") {
		widthdiv = objectlist["width"];
	}
	if (typeof(objectlist["title"])!="undefined") {
		title = objectlist["title"];
	}
	if (typeof(objectlist["but1"])!="undefined") {
		butname = objectlist["but1"];
	}
	if (typeof(objectlist["but2"])!="undefined") {
		but2name = objectlist["but2"];
	}
	if (typeof(objectlist["afterfun"])!="undefined") {
		functionname = objectlist["afterfun"];
	}
	if (typeof(objectlist["isbj"])!="undefined") {
		isbj = objectlist["isbj"];
	}
	if (typeof(objectlist["isanimation"])!="undefined") {
		isanimation = objectlist["isanimation"];
	}

}



if (type=="") {
type = "erro";
}
if (widthdiv=="") {
widthdiv = "400px";
}else{
widthdiv = parseInt(widthdiv)+"px";
if (widthdiv="px") {
widthdiv = "400px";
}
}


if (heightdiv=="") {
heightdiv = "250px";
}else{
heightdiv = parseInt(heightdiv)+"px";
if (heightdiv="px") {
heightdiv = "250px";
}
}

if (butname==""){
butname = "ȷ��";
}
if (but2name=="") {
but2name = "�ر�";
}



var _bj_div = jQuery('<div id="divbj" class="divbj">').css({"position":"absolute","top":"0px","left":"0px","width":$("body").width()
+"px","height":$(document).height()+"px","display":"none","background":"url('/style/img/blackbj.png')"});
$("body").append(_bj_div);

var domthis = $(this);
var _content_div = jQuery('<div id="contentwin" class="contentwin">').css({"width":widthdiv,"height":heightdiv,"z-index":"5000"});
var _div_tl = jQuery('<div class="tl">');
var _div_tr = jQuery('<div class="tr">');
var _div_tc = jQuery('<div class="tc">');
_div_tl.append(_div_tr);
_div_tr.append(_div_tc);
_div_tc.html("<span class=\"title\">"+title+"</span>");
_div_tc.append(" ");

var _div_ml = jQuery('<div class="ml">');
var _div_mr = jQuery('<div class="mr">');
var _div_mc = jQuery('<div class="mc">').css({"padding":"5px","text-align":"left"});
_div_ml.append(_div_mr);
_div_mr.append(_div_mc);
_div_mc.append($(this));
_div_mc.append(" ");

var _div_bl = jQuery('<div class="bl">');
var _div_br = jQuery('<div class="br">');
var _div_bc = jQuery('<div class="bc">').css({"text-align":"center","height":"32px","line-height":"32px"});

var _div_b_but = jQuery('<input type="button" value="'+butname+'">').css({"margin":"4px"});
var _div_b_but2 = jQuery('<input type="button" value="'+but2name+'">').css({"margin":"4px"});

_div_bl.append(_div_br);
_div_br.append(_div_bc);
if (type=="form") {
_div_bc.append(_div_b_but);
_div_bc.append(_div_b_but2);
}
else if (type="erro"){
_div_bc.append(_div_b_but);
}
_div_bc.append(" ");

_content_div.append(_div_tl);
_content_div.append(_div_ml);
_content_div.append(_div_bl);
$("body").append(_content_div);



if (type=="form") {

domthis.find(":submit").css("display","none");
domthis.find(":reset").css("display","none");
//alert(domthis.find(":submit").val());
_div_b_but.click(function(){
	    if (functionname!="") {
		_div_b_but.click(eval(functionname));
		}
domthis.find(":submit").click();

});

_div_b_but2.click(function(){
	_bj_div.css("display","none");
	animation("out");
	//_content_div.fadeOut(500);
});

}
else if (type="erro") {
if (functionname!="") {
_div_b_but.click(eval(functionname));
}
_div_b_but.click(function(){
	_bj_div.css("display","none");
	animation("out");
	//_content_div.fadeOut(500);
});
}

if (showid!="") {
	
$("#"+showid).click(function(){
	if (isbj) {
	_bj_div.css("display","block");
	}
	
	var temp = $(document).width()/2-$("#contentwin").width()/2;
	var temp2= $(document).height()/2-$("#contentwin").height()/2;
	if (document.documentElement.scrollTop>document.body.scrollTop) {
	temp2 = document.documentElement.scrollTop+100;
	}else{
	temp2 = document.body.scrollTop+100;
	}
	_content_div.css({"left":temp+"px","top":temp2+"px"});
	var temp = $(document).width();
	var temp2= $(document).height();
	//$("#showbj").css({"width":temp+"px","height":temp2+"px","display":"block"});
	//_content_div.fadeIn(500);
	animation("in");
});
	
}else{
	if (isbj) {
	_bj_div.css("display","block");
	}
	var temp = $(document).width()/2-$("#contentwin").width()/2;
	var temp2= 0;
	if (document.documentElement.scrollTop>document.body.scrollTop) {
	temp2 = document.documentElement.scrollTop+100;
	}else{
	temp2 = document.body.scrollTop+100;
	}
	_content_div.css({"left":temp+"px","top":temp2+"px"});
	//_content_div.fadeIn(500);
	animation("in");

}


function animation(inout)
{
	if (isanimation) {
	 if (inout=="out") {
	  _content_div.fadeOut(500);
	 }else{
	  _content_div.fadeIn(500);
	 }
	}else{
	 if (inout=="out") {
	  _content_div.css("display","none");
	 }else{
	  _content_div.css("display","block");
	 }
	}
}

}


function showin() {
    //alert($("#contentwin").width());
	var temp = $(document).width()/2-$("#contentwin").width()/2;
	var temp2= $(document).height()/2-$("#contentwin").height()/2;
	temp2 = window.screen.height/8;
	$("#contentwin").css({"left":temp+"px","top":temp2+"px"});
	var temp = $(document).width();
	var temp2= $(document).height();
	$("#showbj").css({"width":temp+"px","height":temp2+"px","display":"block"});
	$("#contentwin").fadeIn(500);
	
	return false;
}
function closewin() {
	$("#contentwin").fadeOut(500);
	$("#showbj").css("display","none");
	return false;
}
