﻿var  divwin={
id:"",
title:"",
content:"",
isWin:[],
proid:false,
cpro:function(){
	//alert($("#processbg").size())

 if(!this.proid){
$("div").eq(0).before("<div><div id=processbg></div></div>")
}
this.proid=true;
},
init:function(id,title,content){
	//初始化之前先隐藏所有的下拉框;
							hideSelect(true);
							 
							 this.cpro();
	                        this.id=id;
							for(var i=0;i<this.isWin.length;i++){
								if(this.isWin[i]==id){
							   //如果打开过，则直接显示，不初始化
							    
								 $('select', "#windowContent"+id).show()

							    this.show();
								return false;
								}
							
							}
							//添加到数组中;
							this.isWin.push(id)
							
							var temp="";
							temp+='<div id="window'+id+'" class=window>'
							temp+='<div id="windowTop'+id+'" class=windowTop>'
							temp+='<div id="windowTopContent'+id+'" class=windowTopContent></div>'
							temp+='<img src="images/window_min.jpg" id="windowMin'+id+'" class=windowMin />'
							temp+='<img src="images/window_max.jpg" id="windowMax'+id+'" class=windowMax />'
							temp+='<img src="images/window_close.jpg" id="windowClose'+id+'" class=windowClose />'
							temp+='	</div>'
							temp+='<div id="windowBottom'+id+'" class=windowBottom><div id="windowBottomContent'+id+'" class=windowBottomContent>&nbsp;</div></div>'
							temp+='<div id="windowContent'+id+'" class=windowContent>'
							temp+='</div>'
							temp+='<img src="images/window_resize.gif" id="windowResize'+id+'" class=windowResize />'
							temp+='</div>' 
							
							
						    this.proid?"":document.body.insertAdjacentHTML("afterBegin","<div><div id=processbg></div></div>");
							this.proid=true;
													 
							$('#'+id).before(temp);							 
							$("#windowTopContent"+id).html(title)
							$("#windowContent"+id).html(content)
							//alert($('#window'+id).css('display'))
							 this.show();
									$('#windowClose'+id).bind(
										'click',
										function()
										{	
										    $("#processbg").hide();
										    hideSelect(false)
											$('#window'+id).TransferTo(
												{
													to:id,
													className:'transferer2', 
													duration: 200
												}
											).hide();
										}
									);
									$('#windowMin'+id).bind(
										'click',
										function()
										{
											$('#windowContent'+id).SlideToggleUp(300);
											$('#windowBottom'+id).animate({height: 10}, 300);
											$('#windowBottomContent'+id).animate({height: 10}, 300);
											$('#window'+id).animate({height:40},300).get(0).isMinimized = true;
											$(this).hide();
											$('#windowResize'+id).hide();
											$('#windowMax'+id).show();
										}
									);
									$('#windowMax'+id).bind(
										'click',
										function()
										{
											var windowSize = $.iUtil.getSize(document.getElementById('windowContent'+id));
											$('#windowContent'+id).SlideToggleUp(300);
											$('#windowBottom'+id).animate({height: windowSize.hb + 13}, 300);
											$('#windowBottomContent'+id).animate({height: windowSize.hb + 13}, 300);
											$('#window'+id).animate({height:windowSize.hb+43}, 300).get(0).isMinimized = false;
											$(this).hide();
											$('#windowMin'+id+',#windowResize'+id).show();
										}
									);
									$('#window'+id).Resizable(
										{
											minWidth: 200,
											minHeight: 60,
											maxWidth: 700,
											maxHeight: 400,
											dragHandle: '#windowTop'+id,
											handlers: {				 
												se: '#windowResize'+id
											},
											onResize : function(size, position) {
											 
												$('#windowBottom'+id).css('height', size.height-33 + 'px');
												$('#windowBottomContent'+id).css('height', size.height-33 + 'px');
												var windowContentEl = $('#windowContent'+id).css('width', size.width - 25 + 'px');
												if (!document.getElementById('window'+id).isMinimized) {
													windowContentEl.css('height', size.height - 48 + 'px');
												}
											}
										}
									);
 
},
resize:function(width,height){
	var size={width:width,height:height}
	id=this.id;
	$('#window'+id).css({height:size.height,width:size.width})
	$('#windowBottom'+id).css('height', size.height-33 + 'px');
												$('#windowBottomContent'+id).css('height', size.height-33 + 'px');
												var windowContentEl = $('#windowContent'+id).css('width', size.width - 25 + 'px');
												if (!document.getElementById('window'+id).isMinimized) {
													windowContentEl.css('height', size.height - 48 + 'px');
												}	
	 	},
show:function(){
			
			$("#processbg").show();
		  	id=this.id
											if($('#window'+id).css('display') == 'none') {
												 
												$("#"+id).TransferTo(
													{
														to:"window"+id,
														className:'transferer2', 
														duration: 200,
														complete: function()
														{
															$('#window'+id).show();
														}
													}
												);
			}			 
			 
		},

close:function(){
	$("#processbg").hide();
	hideSelect(false)
		id=this.id;
		$('#window'+id).TransferTo(
									{
										to:id,
										className:'transferer2', 
										duration: 200
									}
							).hide();
		}
}

 
function hideSelect(t){
	 //selects = document.getElementsByTagName('select');
	// for(i = 0; i < selects.length; i++) {selects[i].style.visibility = visibility;};
 t?$("select").hide():$("select").show()

}