// JavaScript Document
$.Reproductor =	function(player){
	$f(player, "swf/flowplayer.3.1.4.swf",  {
			clip: {autoPlay		: true, backgroundColor: '#FFFFFF', autoBuffering	: true},
			plugins:  {
						controls:  {
								backgroundColor		: '#EDFFB8',		backgroundGradient	: [0.0, 0.3],
								all					: false,			scrubber			: true,
								mute				: true,				play				: true,
								volume				: true,				time				: true,
								fullscreen			: true,				height				: 20,
								autoHide			: 'always',			hideDelay 			: 1500,
								width				: '90%',			bottom				: 5,
								left				: '50%',			borderRadius		: 8,
								opacity				: 1.0,
		
								progressColor		: '#009619',		bufferColor			: '#94D581',
								buttonColor			: '#009619',		buttonOverColor		: '#06BC27',
		
								timeColor			: '#FFFFFF',		timeBorderRadius	: 4,
								timeBgColor			: '#94D581',		durationColor		: "#ffffff",
								volumeSliderColor	: '#94D581',		tooltipColor 		: '#009619',
								tooltipTextColor	: '#FFFFFF',
						tooltips: {
								buttons				: true,				play				: 'Reproducir',
								pause				: 'Detener',		fullscreen			: 'Pantalla Completa'
								}
								
				}
			},time: {
					url					: 'swf/flowplayer.controls-3.1.4.swf',
					top					: 0,
					backgroundGradient  : 'none',
					backgroundColor		: 'transparent',
					buttonColor			: '#E3F4F3',
					buttonTextColor		: '#14555A',
					all					: false,
					time				: true,
					height				: 20,
					right				: 0,
					width				: 100
			},canvas: {
				backgroundColor			: '#FFFFFF'
			},screen: {
				backgroundColor			: '#000000',
				top						: 0
			}
	});

}
$.Play = function(url){
	$f("player").play(url);
}

$(document).ready(function(){
						   
		$.Hover = function(Element){
			 var normalimg = Element.attr("src");
			 var reg = new RegExp("(.+)\\.(gif|png|jpg)", "g");
		 	 var hoverimg = normalimg.replace(reg, "$1_hover.$2");	
			 Element.attr("src",hoverimg)	
		}	
		$.Normal = function(Element){
			 var normalimg = Element.attr("src");
			 var reg = new RegExp("(.+)_hover\\.(gif|png|jpg)", "g");
		 	 var hoverimg = normalimg.replace(reg, "$1.$2");	
			 Element.attr("src",hoverimg)	
		}
		$(".imghover").each(function(){
			 var reg = new RegExp("(.+)\\.(gif|png|jpg)", "g");
		 	 $.Preload($(this).attr("src").replace(reg, "$1_hover.$2"));
		});
		
		window.JOw ={};
		JOw.Page = function(){
			this.Page;
			this.setNombre();
		}
		JOw.Page.prototype.setNombre = function(){
			var cPage = window.location.toString();
			var Name = cPage.substring(cPage.length,cPage.lastIndexOf("/")+1);
			var reg = new RegExp("(.+)\\.(html|php|htm)","g");
			this.Page = Name.replace(reg ,"$1.$2");			
		};
		JOw.Page.prototype.getNombre = function(){
			return this.Page;
		}
						   
		$("#.list_result li").live("mouseover",function(){
			$(this).css({'background':'#F1FFDB','color':'#00AD1F'});											
		}).live("mouseout",function(){
			$(this).css({'background':'white','color':'#175728'});		
		});				   
		$("#menu_principal").html('<div style="position:absolute;padding:0;margin:0">'+
										'<a href="index.html"><img src="images/menu_principal/inicio.jpg" width="218" height="43" alt="Inicio" class="imghover" border="0"/></a>'+
										'<a href="quienes_somos.html"><img src="images/menu_principal/q_somos.jpg" width="218" height="37" alt="Quienes Somos" class="imghover" border="0" /></a>'+
										'<a href="productos.php"><img src="images/menu_principal/productos.jpg" width="218" height="28" alt="Productos" class="imghover" border="0"  /></a>'+
										'<a href="javascript:void(0)"><img id="imgservicios"  onclick="$.ServiciosMenu();" src="images/menu_principal/servicios.jpg" width="218" height="34" alt="Servicios" class="imghover" border="0" /></a>'+
										'<div id="sub_servicios" style="display:none;"> '+
											'<a href="servicios-consumidor_prog_de_beneficios.html"><img src="images/menu_principal/servicios_consumidor.jpg" width="218" height="21" alt="Consumidor" class="imghover"  border="0"   /></a>'+
											'<a href="servicios_medicos_capacitaciones.html"><img src="images/menu_principal/servicios_medicos.jpg" width="218" height="18" alt="Medicos" class="imghover"  border="0"  /></a>'+
											'<a href="servicios_profesionales_de_farmacia_capacitaciones.html"><img src="images/menu_principal/servicios_profesionales.jpg" width="218" height="20" alt="Profesionales de Farmacia" class="imghover"  border="0"   /></a>'+
										'</div>'+
										'<a href="noticias.html"><img src="images/menu_principal/noticias.jpg" width="218" height="35" alt="Noticias" class="imghover" border="0" /></a>'+
										'<a href="trabaje_con_nosotros.html"><img src="images/menu_principal/trabaje_con_nosotros.jpg" width="218" height="33" alt="Trabaje con Nosotros" class="imghover" border="0"  /></a>'+
										'<a href="enlaces_de_interes.html"><img src="images/menu_principal/enlaces_de_interes.jpg" width="218" height="33" alt="Enlaces de Interes" class="imghover" border="0"  /></a>'+
										'<a href="zona_segura.html"><img src="images/menu_principal/zona_segura.jpg" width="218" height="34" alt="Zona Segura" class="imghover" border="0"  /></a>'+
										'<a href="contactenos.html"><img src="images/menu_principal/contactenos.jpg" width="218" height="23" alt="Contactenos" class="imghover" border="0" /></a>'+
										'</div>');	
		var PaginaActual = new JOw.Page();
		var MenuActive = $("#menu_principal div a");
		MenuActive.each(function(){
			var ListHrefMenu = ($(this).attr("href"));	
			if(PaginaActual.getNombre()==ListHrefMenu){
				$(this).attr("href","javascript:void(0)");
				hreimgpage  = $(this).find("img")
				$.Hover(hreimgpage);
				hreimgpage.removeClass("imghover");
			}
			if(PaginaActual.getNombre().substring(0,9)=="servicios"){
				$("#sub_servicios").slideDown();	
				$("#imgservicios").attr({"src":"images/menu_principal/servicios_hover.jpg","class":""});
			};
		})
		$(".imghover").hover(function(){$.Hover($(this))},function(){$.Normal($(this))});
		$.ServiciosMenu = function(){$("#sub_servicios").slideToggle();}
		JOw.Producto = function(){ 
				this.Id;
				this.Data;
				this.Content;
				this.Message="<center><div style='font:10px arial;width:200px;height:200px;margin:80px auto;color:#6E8C42'>"+
										"<img src='images/25.gif' /><br/>Cargando...</div>"+
							 "</center>";
		}
		JOw.Producto.prototype.setId = function(Id){ 
				this.Id = Id;
		}
		JOw.Producto.prototype.getId = function(){ 
				return this.Id;
		}
		JOw.Producto.prototype.setContent = function(Content){ 
				this.Content = Content;
		}
		JOw.Producto.prototype.getContent = function(){ 
				return this.Content;
		}
		JOw.Producto.prototype.getData = function(){ 
				inst = this;
				inst.getContent().html(inst.Message);
				$.post("_data.php",{Task : 'Buscar' , Id : this.getId()},function(response){
					setTimeout(function(){
						inst.getContent().html(response);				
					},200)
					$.Log("Mostrando Producto")
				})
		}
		
		var objp = new JOw.Producto();
		objp.setContent($("#contenido_pop_aranda"));
		
		$.VerProducto = function(Producto){
			objp.setId(Producto);
			objp.getData();
		}
		
		$.VerVademecum = function(Producto){
			window.open("vademecum/?ProductId="+Producto,"VADEMECUM","width=830,height=610,menubar=no,location=no,resizable=no,scrollbars=yes,status=no");            
		}
		$.VerPdf = function(File){
			 $.CreateCookie( "file", File , 30 );
			 window.open("vademecum/pdf.php","VADEMECUM","width=830,height=610,menubar=no,location=no,resizable=no,scrollbars=yes,status=no");
			 
		}
		
		JOw.Buscar = function(){
			this.Input;
			this.Resultado;
			this.Caracteres;
		}
		JOw.Buscar.setInput = function(){
			
		}
		JOw.Buscar.setCaracteres = function(){
			
		}
	var itemsresultnumber = 0;	
	$("#txtbuscar").keyup(function(e){
		var code = (e.keyCode ? e.keyCode : e.which);
		var currenttext = $(this).val();
		var ResultInput = $("#resultado_busqueda");
		var ResultAll   = $(".ResultAll");
		var VerCurrentResult = 0;
		if(code > 48 && code < 100 ){
			if(currenttext.length >= 3){
				$.getJSON("_buscar.php",{Text : currenttext},function(Result){
					if(Result.length > 0){
						itemsresultnumber = Result.length;
						var ResultList="<ul class='list_result' >";
						for(var i in Result){ResultList += "<li><a href='productos.php?ProductId="+Result[i].id+"'>"+Result[i].nombre+"</a></li>";}	
						ResultList +="</ul>";
						ResultInput.html(ResultList);
						ResultInput.slideDown();
						$("#txtbuscar").mouseover(function(){
							ResultInput.slideDown();
						});
						ResultInput.hover(function(){
							ResultInput.slideDown();
							VerCurrentResult=0;
						},function(){
							VerCurrentResult=1;
							setTimeout(function(){
								if(VerCurrentResult==1){
									ResultInput.slideUp();
								}
							},500);									  
						});
						$("#divresult").html(Result.length+" producto encontrados!.").fadeIn();
						$.Log("Busqueda '"+currenttext+"' "+Result.length+" resultados. ",{clear:true});
					}else{
						itemsresultnumber=0;
						$.Log("No se encontraron resultados.",{clear:true});
						$("#divresult").html("No se encontro ningun resultado!.").fadeIn();
					}
				})
			}else{
				$("#resultado_busqueda").slideUp();
				ResultInput.html("");
				//$("#divresult").html("No se encontro ningun resultado!.").fadeIn();
				itemsresultnumber=0;
			}
		}else{
			ResultInput.html("").hide();
			$("#divresult").hide();
			itemsresultnumber=0;
		}
	});
	
	$("#txtbuscar").Mask({Texto : "Nombre del producto"});
	$("#btnbuscar").click(function(){
		if(itemsresultnumber==0){
			$("#divresult").html("Escribe un producto en la casilla de texto!.")
		}
		if($("#txtbuscar").val()=="Nombre de Producto"){
			$("#divresult").html("Escribe un producto en la casilla de texto!.")
		}
		$("#divresult").fadeOut().fadeIn();
	})

})



