// JavaScript Document
(function($){
	$.fn.extend({
		Llight_create: function() {
					//Crea el Fondo
						objeto_ventana=$(this);
						tamanio_width='100%';
						if (typeof document.body.style.maxHeight === "undefined") { // es IE 6
								$("body","html").css({height: "100%",width: '100%'});	
								tamanio_width=$(window).width();
							}			
						tamanio_height=$(document).height();
						id_objeto_ventana=objeto_ventana.attr("id");
		
						overlay = $("<div id='modal-overlay' style='z-index:499; padding:0; margin:0; border:none;'></div>").css({
							position: 'absolute',
							top: '0px',
							left: '0px',
							background: '#000',
							display: 'none',
							height: tamanio_height,
							width: tamanio_width
						}).attr("Llightattr",id_objeto_ventana);
							objeto_ventana.centrar_objeto();
							$(overlay.click(function(overlay){ $(objeto_ventana).Llight_destroy();})).appendTo(document.body);
							overlay.css("opacity", 0.6);
							overlay.fadeIn(600);
							$(objeto_ventana).css({display:"none", visibility:"visible"});
							objeto_ventana.fadeIn(600);
							objeto_ventana.Llight_resize();
					/*      Tecla ESC  ***********/
							$(document).keypress(function (e) {
							  if (e.which == 0 || e.which == 27) {
								$(objeto_ventana).Llight_destroy();
							  }
							});
					/*      Tecla ESC  **********/
							return objeto_ventana;
						},
					//Funcion Cerrar y Centrar
					Llight_destroy: function(){
						objeto_cerrar=$(this);
						attr_light=$(overlay).attr("Llightattr");
						var remove = function() { $(overlay).remove(); };
						overlay.fadeOut(600,remove);
						if(attr_light!=""){ objeto_cerrar=$("#"+attr_light); }
						
						objeto_cerrar.fadeOut(600);
						return $(this);
					},centrar_objeto: function(){ 
						var wnd = $(window), doc = $(document),	pTop = doc.scrollTop(), pLeft = doc.scrollLeft(), minTop = pTop;
						pLeft += parseInt((wnd.width() - $(this).width()) / 2); if(pLeft<0){ pLeft=0;  }
						pTop += parseInt((wnd.height() - $(this).height()) / 2); if(pTop<5){ pTop=5;  }
						$(this).css({top: pTop, left: pLeft}); 
					},Llight_resize: function(){
					
							objeto_ventana=$(this);
							tamanio_width='100%';
							if (typeof document.body.style.maxHeight === "undefined") { // es IE 6
									$("body","html").css({height: "100%",width: '100%'});	
									tamanio_width=$(window).width();
								}			
							tamanio_height=$(document).height();
							id_objeto_ventana=objeto_ventana.attr("id");
							
							$('#modal-overlay').css({
							height: tamanio_height,
							width: tamanio_width   });
							
							
					}
		});
})(jQuery);


function abrirVideoPublicidad(){
	$('<div id="video_publicidad"><a id="cerrar_video"></a><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="350" height="290" id="flashVideo"><param name = "allowScriptAccess" value = "always" /><param name="movie" value="flash/video_publicidad.swf" /><param name="quality" value="high" /><param name="wmode" value="opaque" /><param name="scale" value="noscale" /><param name="salign" value="lt" /><param name="swfversion" value="8,0,0,0" /><embed src="flash/video_publicidad.swf" width="350" height="290" name="flashVideo"></embed></object></div>').prependTo('body');
	$('#video_publicidad').Llight_create().centrar_objeto();						
	/* Insertar bloque de video publicitario en el DOM (aparece oculto por defecto gracias a CSS), hacerlo aparecer y centrarlo */
	//Función de parada y eliminación video
	$('#cerrar_video').live("click",function() {
		//callExternalInterface(); // Llamar a flash para parar video
		$('#video_publicidad').Llight_destroy().remove();
	});
	return;
}


$(document).ready(function(){
		
		$('#unicef_masinfo').click(function(){
												$('#unicef_masinfo_ventana').Llight_create().centrar_objeto();
											});
		$('#unicef_masinfo_central').click(function(){
												$('#unicef_masinfo_ventana').Llight_create().centrar_objeto();
											});
		
		$('#unicef_masinfo_ventana').click(function(){
														$('#unicef_masinfo_ventana').Llight_destroy();
													});
						   
						   
		$('.mas_info_gafas_exp').click(function(){
			$('#mas_info_gafas').Llight_create().centrar_objeto();
		});

		$('.cerrar_mas_info_gafas').click(function(){
			$('#mas_info_gafas').Llight_destroy();
		});
		
		$('#email_newsletter_suscribe').click(function(){ if($(this).attr("value")==' email... '){ $(this).attr("value","");  }   });


		$('.regalo_con_imagen').hover(function(){ regalo_id=$(this).attr('id');
												  regalo_id=regalo_id.replace('regalo_','');
												  regalo_id="regalo_imagen_"+regalo_id;
												  
												  arriba2=$(this).offset().top;
												  izquierda=$(this).offset().left;
												  izquierda=izquierda-12;
												  izquierda_flecha=izquierda-5;
												  izquierda=izquierda-530;
												  arriba_flecha=arriba2;
												  arriba2=arriba2-70;
												  $('#'+regalo_id).css('left',izquierda+'px');
												  
												  $(this).mousemove(function(e){
																		arriba2=e.pageY-200;
												  						$('#'+regalo_id).css('top',arriba2+'px');
																	});
												  $('#'+regalo_id).css('display','block');
												  
												  },function(){
												   $('.regalo_imagen').css('display','none');
											   });


});
