var j21H=600;

$(document).ready(
	function()
	{
		$.history._cache = '';
		$('#windowOpen').bind(
			'click',
			function() {
					
					$('#mask').fadeIn(500);
					$('#mask').fadeTo("slow",0.8);
					$('#mask').show();
					$('#window').css('visibility','visible');
					$('#window').fadeIn(1000);
					$('#window').show();
					black();

					this.blur();
					return false;
			}
		);
		$('#windowClose').bind(
			'click',
			function()
			{
				$('#mask').hide();
				$('#window').TransferTo(
					{
						to:'windowOpen'
					}
				).hide();
			}
		);
		$('#windowMin').bind(
			'click',
			function()
			{
				$('#windowContent').SlideToggleUp(j21H);
				$('#windowBottom, #windowBottomContent').animate({height: 10}, j21H);
				$('#window').animate({height:30},j21H).get(0).isMinimized = true;
				$(this).hide();
				$('#windowResize').hide();
				$('#windowMax').show();
			}
		);
		$('#windowMax').bind(
			'click',
			function()
			{
				var windowSize = $.iUtil.getSize(document.getElementById('windowContent'));
				$('#windowContent').SlideToggleUp(j21H);
				$('#windowBottom, #windowBottomContent').animate({height: windowSize.hb + 13}, j21H);
				$('#window').animate({height:windowSize.hb+43}, j21H).get(0).isMinimized = false;
				$(this).hide();
				$('#windowMin, #windowResize').show();
			}
		);
		$('#window').Resizable(
			{
				//minWidth: 200,
				//minHeight: 60,
				//maxWidth: 700,
				//maxHeight: j21H,
				dragHandle: '#windowTop',
				handlers: {
					se: '#windowResize'
				},
				onResize : function(size, position) {
					if (size.height<30) size.height=30;
					if (size.width<150) size.width=150;
					$('#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');
					}
				}
			}
		);
		$('#windowReload').click(function(){
			alert("hihi");
			location.reload();
		});
	}

);
function getViewportSize() {
    var x, y;
    if (self.innerHeight) { // MOS
        y = self.innerHeight;
        x = self.innerWidth;
    } else if (document.documentElement && document.documentElement.clientWidth) { // IE6 Strict
        x = document.documentElement.clientWidth;
        y = document.documentElement.clientHeight;
    } else if (document.body.clientHeight) { // IE quirks
        y = document.body.clientHeight;
        x = document.body.clientWidth;
    }
    return {x: x, y: y};
}
function black()
{
	if ($('#window').css('visibility')=='visible')
	{
		if ($('#window').css('width')!='auto')
		{
			winW=$(window).scrollLeft()+($(window).width()-parseInt($('#window').css('width')))/2;
			winH=$(window).scrollTop()+($(window).height()-parseInt($('#window').css('height')))/2;
			if (winW<=0) winW=10;
			if (winH<=0) winH=10;
			$('#window').css({'left':winW,'top':winH});

			//Set heigth and width to mask to fill up the whole screen
			$('#mask').css({'left':$(window).scrollLeft(),'top':$(window).scrollTop(),'width':$(window).width(),'height':$(window).height()});

		}
		//transition effect
	}
}
function WindowShow(url, titulo, ancho, alto, op)
{
	ancho=parseInt(ancho);
	alto=parseInt(alto);
	j21H=alto;
	
	alto2=alto+43;
	ancho2=ancho+25;
	$('#window').css('width',ancho2+"px");
	$('#window').css('height',alto2+"px");
	$('#windowTopContent').html(titulo);
	$('#windowContent').html("cargando....<br>["+url+"]");
	$('#windowContent').css('width',ancho+"px");
	$('#windowContent').css('height',alto+"px");
	//$('#windowBottom').css('height',alto2+"px");
	
	alto2=alto+20;
	//$('#windowBottomContent').css('height',alto2+'px');

	if (op==1)
	{
		data='<iframe marginwidth="0" marginheight="0" frameborder="0" src="'+eval(url)+'" style="position:absolute; left:-10px;top:-10px;width:100%;height:100%" frameborder="NO" framespacing="0"></iframe>';
		$('#windowContent').html(data)
	}
	else
	{
		$.get(eval(url),function(data){
			$('#windowContent').html(data);
		});
	}

	$('#windowBottom, #windowBottomContent').css('height', alto2-5 + 'px');
	var windowContentEl = $('#windowContent').css('width', ancho2 -25 + 'px');

	$('#windowMax').hide();
	$('#windowMin, #windowResize').show();
	$('#windowOpen').click();
}

