﻿var currentObj;

$(document).ready(
	function()
	{
		openDialog = function(obj,titre,contenu) { 	
		currentObj=	obj;	 
		 if($('#window').css('display') == 'none') {
		     $('#windowTopContent').text(titre);		 
		     $('#windowContent').html(contenu);
		     $(obj).TransferTo(
						    {
							    to:'window',
							    className:'transferer2', 
							    duration: 400,
							    complete: function()
							    {
								    $('#window').show();
								   
							    }
						    }
					    );
          }
          
		  return false;
		}; 
		
	
	resizeDialog = function(width,height) { 
	width +=30;
	height+=30;
	maxWidth= 700;
    maxHeight= 700;
    
    if(width>=maxWidth) width = maxWidth;
    if(height>=maxHeight)  height=maxHeight ;  
      
    $('#window').css('width', (width + 30) + 'px');	
    $('#window').css('height', (height + 50) + 'px');  
    $('#windowContent').css('width', (width + 5) + 'px');	
    $('#windowContent').css('height', (height + 5) + 'px');	
    $('#windowBottom, #windowBottomContent').css('height', (20+height) + 'px');
	
	};
		
		$('#windowClose').bind(
			'click',
			function()
			{			    
				$('#window').TransferTo(
					{
						to:currentObj,
						className:'transferer2', 
						duration: 400
					}
				).hide();
				 $('#windowContent').html("&nbsp;");
			}
		);
		$('#windowMin').bind(
			'click',
			function()
			{
				$('#windowContent').SlideToggleUp(300);
				$('#windowBottom, #windowBottomContent').animate({height: 10}, 300);
				$('#window').animate({height:40},300).get(0).isMinimized = true;
				$(this).hide();
				$('#windowResize').hide();
				$('#windowMax').show();
			}
		);
		$('#windowMax').bind(
			'click',
			function()
			{
				var windowSize = $.iUtil.getSize(document.getElementById('windowContent'));
				$('#windowContent').SlideToggleUp(300);
				$('#windowBottom, #windowBottomContent').animate({height: windowSize.hb + 13}, 300);
				$('#window').animate({height:windowSize.hb+43}, 300).get(0).isMinimized = false;
				$(this).hide();
				$('#windowMin, #windowResize').show();
			}
		);
		$('#window').Resizable(
			{
				minWidth: 200,
				minHeight: 60,
				maxWidth: 700,
				maxHeight: 700,
				dragHandle: '#windowTop',
				handlers: {
					se: '#windowResize'
				},
				onResize : function(size, position) {
					$('#windowBottom, #windowBottomContent').css('height', size.height-33 + 'px');
					var windowContentEl = $('#windowContent').css('width', size.width - 25 + 'px');
					if (!document.getElementById('window').isMinimized) {
						windowContentEl.css('height', size.height - 48 + 'px');
					}
				}
			}
		);
	}
);
