/* PR 2007 - 2010 */
function timeoutfunction () {

}

var inputDelayer=delayTimer(200);	


$(window).resize(function() {
	/*
		inputDelayer(function(){
			timeoutfunction();
		});	
	*/
	
	/* resizen berechnung viewports aus xajax */
	if($("#nyroModalContent").html()){
		margin = 20;
		shadow = 20;
		horizontal_space	= (shadow + margin) * 2;
		vertical_space		= (shadow + margin) * 2;
		double_padding		=  0;
		newwidth = (($(window).width() * parseFloat(facywidth)) / 100) - (shadow * 2) ;
		newwidth	= Math.min(newwidth, ($(window).width() - horizontal_space));
		 
		newheight = (($(window).height() * parseFloat(facyheight)) / 100) - (shadow * 2); 
		newheight	= Math.min(newheight, ($(window).height() - vertical_space));
			 
		$("#fancybox-wrap").css({
			"height" :  newheight,
			"width" : newwidth
		});	
		$("#fancybox-inner").css({
			"height" :  newheight,
			"width" : newwidth
		});	
		
		wrapfancy();
		$.fancybox.center();
	}
});

function openModal(edit_elem, width, height, tiny, title, no_close){
		

	var newcon = "<div id='nyroModalContent'>"+elementObject['ModalOpenerHtml']+"</div>";
	/* jQuery.fx.off = true; */

	/* viewports for resize */
	facywidth = width;
	facyheight = height;
	
	
	if(!title){
		var title = '';	
	}
	
	if(no_close)
	{
		var no_close = 0;	
	}else{
		var no_close = 1;	
	}
	
	$.fancybox({
		'content':newcon,
		'modal': true,
		'autoDimensions': false,
		'width': width, // Minimum width
		'height': height, // Minimum height
		'titlePosition'		: 'inside',
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'padding': 0,
		'scrolling' : 'no',
		'onClosed' : function(){
			$("body #admin_panel_nyro").show();	
			$("html").css({
				"overflow" : "auto"
			});	
		},
		'onStart': function(){
				
				$("#fancybox-outer").css({
					"background" : "#FFF"
				});	
				$("body #admin_panel_nyro").hide();	
				$("html").css({
					"overflow" : "hidden"
				});	
				
				/* schatten ausblenden */
				$("#fancy-bg-n").remove();	
				$("#fancy-bg-ne").remove();	
				$("#fancy-bg-e").remove();	
				$("#fancy-bg-se").remove();	
				$("#fancy-bg-s").remove();	
				$("#fancy-bg-sw").remove();
				$("#fancy-bg-w").remove();
				$("#fancy-bg-nw").remove();	
				
		},
		'onComplete': function(){
			
			setTimeout(function(){
				wrapfancy();
				$("#nyroModalContent").children().eq(1).remove();
								
			}, 1);
			
		}
	});


	if(tiny == 1)
	{
		if(height && width){
			var height = height - 70;
			var width = width + 174;
		}else{
			var height = "500";
			var width = "500";
		}
		setTimeout(function(){starttiny(edit_elem, width, height);},200);
	}
}


function wrapfancy(){
	
	 /* berechnungen der Steuereinheiten & Scollbars */

	  $("#nyroModalContent").css({
		  "height" : ( $("#fancybox-inner").height())
	  });	
	  $("#nyroModalContent").css({
		  "height" : ( $("#fancybox-inner").height())
	  });	
	  $("#fancybox-outer").css({
		  "background" : "transparent"
	  });	

	  if( $(".content_split .content_left").length > 0 && $(".content_split .content_right").length > 0  ){
		  $("#nyroModalContent .content_split").css({
			  "height" : ( $("#fancybox-inner").height() - $("#admin_panel_nyro").height() -2 ),
			  "min-height" : "20px"
		  });	
		  $("#nyroModalContent .content_left").css({
			  "overflow-y": "auto",
			  "height" : ( $("#fancybox-inner").height() - $("#admin_panel_nyro").height() -22 ),
			  "min-height" : "20px"
		  });	
		  $("#nyroModalContent .content_right").css({
			  "overflow-y": "scroll",
			  "height" : ( $("#fancybox-inner").height() - $("#admin_panel_nyro").height() -22 ),
			  "min-height" : "20px",
			  "width": ( $("#fancybox-inner").width() - 440 )
		  });
		  
	  }else if ($(".content_split").length > 0){
		  $("#nyroModalContent .content_split").css({
			  "overflow-y": "scroll",
			  "height" : ( $("#fancybox-inner").height() - $("#admin_panel_nyro").height() -2 ),
			  "min-height" : "20px"
		  });	
	  
	  }else{

	  }
}

function starttiny(elem, tiny_width, tiny_height){
	/* TinyMce über Function starten toggleEditor in apps/tiny_mce/ */
	toggleEditor(elem, tiny_width, tiny_height);
}
