// JavaScript Document

/*
	Author : Nick Cyrus Lemus Duque
	16 FEB 2010
*/

(function ($) {
	
	var $lightboxUni,
	$overlay,
	$iframe,
	$window = $(window),
	$body   = $('body');
	
	defaults = {
		iframeheight: false,
		iframewidth: false,
		overlayClose : true,
		ajustarTop : 0,
		ajustarBotton : 0,
		initialWidth: "800",
		initialHeight: "600",
		opacity: 1,
		url : '',
		preloading: true,
		next: "next",
	};
	
	
	
	$.fn.ligtboxpulpo = function (options, callback) {
			
			var property = $.extend({}, defaults, options);		
			//$(this).click(function(e){
				var href;
				
				(property.url) ? href=property.url  : href=this.href;
				
				if (href){
						
						$overlay  = '<div id="overlayUni"></div>';
						
						var height = (property.iframeheight) ? property.iframeheight : property.initialHeight;
						var width = (property.iframewidth) ? property.iframewidth : property.initialWidth;
						
						
						height  = setSize(height , 'y');
						width = setSize(width,'x');	
						
						
						$iframe  = '<div id="Icontent" style="height:'+height+'px;width:'+width+'px;"><div id="iclose"></div><iframe allowtransparency="yes" frameborder="0" height="100%" width="100%" scrolling="auto" id="iFrameUniform" name="iFrameUniform" src="'+href+'" style="display:none"></iframe><br style="clear:both;" /></div>';
						
						//$ilogo = '<div id="ilogo"></div>';
						
						
						$('body').prepend($overlay);
						$('#overlayUni').after($iframe)
						
						/*$('body').css({
									  	overflow : 'hidden'/*,
										/*'z-index': 9999*/
						//		  })
						
						var Size = getSizeBody();
						var SizeWindow = getSizeWindow();
						
						
						
						
						$('#overlayUni').css({
											 	width    : SizeWindow[0],
												height   : SizeWindow[1]-property.ajustarBotton,
												position : 'absolute',
												top		 : property.ajustarTop+'px',
												left     : '0px',
												opacity  : property.opacity,
												'z-index': 0
											})
						
						
						$('#iFrameUniform').load(function(){
							posiciona();
							$('#iFrameUniform').fadeIn(500);
							$('#overlayUni').css('background','none');
						})
						
						
						//posTop = 55
						posTop = ((SizeWindow[1]/2)-(height/2))//+$window.scrollTop(),
						
						//posLeft = ((SizeWindow[0]/2)-(width/2))//+$window.scrollLeft();
						posLeft = ((SizeWindow[0]-width)/2)+140;
		
						
						
						$('#Icontent').css({
												position : 'absolute'
											 })
						
						
						
						/***************/	
						//'window'
						$(window).resize(function(){
							
							var Size = getSizeBody();
							var SizeWindow = getSizeWindow();
							
							$('#overlayUni').css({
											 	width    : '100%',
												height   : '100%',
												position : 'absolute',
												top		 : '0px',
												left     : '0px',
												opacity  : property.opacity
							})
							
							
							
						
							posTop = ((SizeWindow[1]/2)-(height/2))+$window.scrollTop()
							//posLeft = ((SizeWindow[0]/2)-(width/2))+$window.scrollLeft();
							
							posLeft = ((SizeWindow[0]-width)/2)+140;
							
							/*
							$('#Icontent').css({
												/*top 	 : posTop,
												left     : posLeft
												
							 },500)
							*/
							
						})
						/*
							Close overlay
						*/
						if (property.overlayClose){
							$('#overlayUni').click($.fn.close);
						}
						
						$('#iclose').click($.fn.close);
						
						
						//alert(getSizeWindows());
				
				 // End href
				}

				//e.preventDefault();
			//})
	
	// End Función
	}
	
	$.fn.close = function(){
					
					var URL = $('#iFrameUniform').attr('src');
					
					URL = (URL) ? URL : 0;
					
					$('#iFrameUniform').fadeOut(500, function(){
													$('#overlayUni').fadeOut(200, function(){
																										
															//if (URL=='php/import.php'){
																//parent.thisMovie('content').closeReto();
															// }else{
																//thisMovie('content').closeLightbox();
															// }
															
															$('#overlayUni,#iFrameUniform,#Icontent').remove()
													})
													
													$('#Icontent, #overlayUni').remove();
					})
			// e.preventDefault();
	}
	
	$.fn.simpleclose = function(e){
					$('#iFrameUniform').fadeOut(500, function(){
													$('#overlayUni').fadeOut(200, function(){
															$('#overlayUni,#iFrameUniform,#Icontent').remove();
															// thisMovie('content').closeLightbox();

													})
								$('#Icontent').remove();
					})
			// e.preventDefault();
	}
	$.fn.closeNocallback = function(e){
					$('#iFrameUniform').fadeOut(500, function(){
													$('#overlayUni').fadeOut(500, function(){
															$('#overlayUni,#iFrameUniform,#Icontent').remove();
															// thisMovie('content').closeLightbox();

													})
								$('#Icontent').remove();
					})
			// e.preventDefault();
	}
	
	// Convert % values to pixels
	function setSize(size, dimension) {
		dimension = dimension === 'x' ? $window.width() : $window.height();//document.documentElement.clientWidth : document.documentElement.clientHeight;
		return (typeof size === 'string') ? Math.round((size.match(/%/) ? (dimension / 100) * parseInt(size, 10) : parseInt(size, 10))) : size;
	}

	getSizeWindow=function(){
		
		width = $(window).width();
		height = $(window).height();
		var Size = new Array(width,height);
		return Size;
	}
	
	getSizeBody=function(){
		
		width = $('body').width();
		height = $('body').height();
		var Size = new Array(width,height);
		return Size;
	}
	
	
}(jQuery));


