﻿var mylan = 
{
	init : function()
	{
		// Acciones para que se muestre el submenú de "¿Quieres saber más?"
		//var sm_mouseover = function(){	jQuery("#submenu_3").fadeIn(100);	},
			//sm_mouseout = function(){	jQuery("#submenu_3").fadeOut(100); 	}
		
		//jQuery("#menu_option3 A:first").mouseover(sm_mouseover);
		//jQuery("#submenu_3").mouseout(sm_mouseout);
		
		
		// Genera una lista de "las palabras más buscadas"
		var MAX_NUM_RESULTS = 5,
			RANDOM_STYLES = 5; // Nº de estilos "SPAN.randomKey#" en styles.css
		var KEYWORDS = [
						"Atención hospitalaria",
						"Vademécum hospitalario",
						"Laboratorio farmacéutico",
						"Medicamentos Genéricos",
						"Vademécum Especialistas",
						"Hospitalario",
						"Atención primaria",
						"Mylan"
						];		
		var temp_keywords = [];
		
		for(var i=0; i<MAX_NUM_RESULTS; i++)
		{
			temp_keywords.push( 
				"<span class='randomKey" + Math.round(Math.random()*(RANDOM_STYLES-1)) + "'>" +
				KEYWORDS.splice( Math.round(Math.random()*(KEYWORDS.length-1)), 1 )[0] +
				"</span>"
			);
		}
		
		jQuery("#footer_mostSearched_result").html(temp_keywords.join(", "));
	},
	
	
	Home : 
	{
		vademecumURL : "",
		
		// Inicializa el alert de la home al clickar en el menú de productos
		init : function()
		{
/*			var productos_links = jQuery("#homeMenuBox2 A"),
				clickHanlder = function()
				{
					mylan.Home.vademecumURL = this;
					
					jQuery("#alert_blocker").show();
					jQuery("#alert_blocker").fadeTo(200, 0.4);
					jQuery("#home_alert").fadeIn(200);
					
					return false;
				};
			
			// Oculta la capa para IE (si no la primera vez que aparece lo hace en negro opaco
			jQuery("#alert_blocker").fadeTo(0, 0);
			
			for(var i=0; i<productos_links.length; i++)
				jQuery(productos_links[i]).click( clickHanlder );
*/		},
		
		// Oculta el alert de la home
		hideAdvice : function()
		{
			jQuery("#alert_blocker").fadeTo(100, 0, function(){ jQuery("#alert_blocker").hide(); });
			jQuery("#home_alert").fadeOut(100);
		},
		
		// Navega hasta la página de vademécum si el checkbox está seleccionado
		gotoVademecum : function()
		{
			if( jQuery("#soy_profesional").attr("checked") )
				document.location = mylan.Home.vademecumURL;
			else
				alert("Si eres un profesional sanitario con capacidad de prescripción\no dispensación en España selecciona la casilla correspondiente.");
		}
	},
	
	
	Donde :
	{
		map: {},
		// Debem coincidir con el orden del los elementos del <select> en la página "donde_estamos.html"
		locations: [
			["Mylan España",	"Carrer del Plom, 2-4<br />08038 - Barcelona<br />Spain"],
			["Bilbao",			"Cámara de Comercio-Mylan<br />C/ Alameda de Recalde, 50, 3ª Planta, Despacho 3.05<br />Telf. 944-70.64.10<br />Fax 944-70.64.01"],
			["Madrid",			"C/ Nuñez de Balboa, 120, bajo dcha.<br />28006 - Madrid<br />Telf. 91-411.68.18"],
			["Sevilla",			"Centro de Negocios Cristina<br />Paseo de las Delicias, 1, 2ª Planta<br />41001 - Sevilla<br />Telf. 954-501.376<br />Fax 954-560.857"],
			["Valencia",		"Edificio Géminis Center<br />Avda. Cortes Valencianas, 39, planta 1ª, Despacho 34<br />46015 - Valencia<br />Telf. 96-119.96.84<br />Fax 96-119.96.01"],
			["Granada",			"C/ San Antón, 4, 1º, Oficina 3<br /> 18005 – Granada <br />Telf. 958 25.10.48"],
			["Almacén",			"Polígono Industrial de Lliçà d’Amunt<br />C/ Bosc de la Riera, 23<br />08186- LLiçà d’Amunt (Barcelona)"]
		],
		
		init : function()
		{
			if(GBrowserIsCompatible())
			{
				mylan.Donde.map = new GMap2(document.getElementById("donde_map"));
				mylan.Donde.map.setUIToDefault();		
				mylan.Donde.setMapLoc( mylan.Donde.parseLoc(jQuery('#delegaciones option')[1].value) );
				
				jQuery('#donde_ir').click(function()
				{
					var idx = jQuery('#delegaciones').attr("selectedIndex");
					if(idx != 0)
					{
						mylan.Donde.setMapLoc( mylan.Donde.parseLoc( jQuery('#delegaciones option')[idx].value ) );
						jQuery("#donde_info_content > *").fadeOut(100, function()
						{
							jQuery("#donde_info_content H2").html( mylan.Donde.locations[idx-1][0] );
							jQuery("#donde_info_content P B").html( mylan.Donde.locations[idx-1][1] );
							
							jQuery("#donde_info_content > *").fadeIn(100);
						});
					}
				});
			}
			jQuery("#footer_links .thickbox").click(function(){
				jQuery("select").hide();
			});
			jQuery("#alert_box #alert_buttons a.button").click(function(){
				jQuery("select").show();
			});
		},
		
		parseLoc : function(point_str)
		{
			var loc = point_str.split(",");
			return new GLatLng(loc[0], loc[1]);
		},
		
		setMapLoc : function(point)
		{
			mylan.Donde.map.setCenter(point, 15);
			mylan.Donde.map.addOverlay(new GMarker(point));
		}
	},
	
	
	FAQ : 
	{
current : undefined,

		init : function()
		{
			jQuery("#faq_list LI").css("cursor", "pointer");
			jQuery("#faq_list LI DIV").hide();
			
			var lis = jQuery("#faq_list LI"),
				liHandler = function()
				{
					if(jQuery(this).children("DIV:first").is(":hidden"))
						mylan.FAQ.show( this );
						
					else
						mylan.FAQ.hide( this );
				};
				
			for(var i=0; i<lis.length; i++)
				jQuery(lis[i]).mouseup(liHandler);
		},

		show : function(target)
		{
			jQuery(target).children("DIV:first").slideDown(100);
			jQuery(target).children("B.faq_question SPAN:first").addClass("close");
			
			if(mylan.FAQ.current && mylan.FAQ.current != undefined && mylan.FAQ.current != target)
				mylan.FAQ.hide(mylan.FAQ.current);
			
			mylan.FAQ.current = target;
		},

		hide : function(target)
		{
			jQuery(target).children("DIV:first").slideUp(100);
			jQuery(target).children("B.faq_question SPAN:first").removeClass("close");
		}
	},
	
	
	VM : 
	{
		init : function()
		{
			//var DEF_VALUE = "Buscar palabra clave";
			var DEF_VALUE = jQuery('INPUT.vm_search_string:first').attr("defaultValue");
			if(DEF_VALUE == "" || DEF_VALUE == undefined) DEF_VALUE = "Escribe una palabra clave";

			jQuery('INPUT.vm_search_string').each(function()
			{
				jQuery(this).focus(function()
				{
					if(this.value == DEF_VALUE) this.value = "";
				});
				
				jQuery(this).blur(function()
				{
					if(this.value == "") this.value = DEF_VALUE;
				});
			});
		},
		
		initFT : function()
		{
			jQuery("#vmft_descr OL LI").css("cursor", "pointer");
			jQuery("#vmft_descr OL LI DIV").hide();
			
			var lis = jQuery("#vmft_descr OL LI"),
				liHandler = function()
				{
					var	contentDIV = jQuery(this).children("DIV:first");
					
					if(contentDIV.is(":hidden"))
					{
						contentDIV.slideDown(100);
					}
					else
					{
						contentDIV.slideUp(100);
					}
				};
				
			for(var i=0; i<lis.length; i++)
				jQuery(lis[i]).mouseup(liHandler);
				
			jQuery("#vmf_ficha UL LI SPAN.open_info").click(function(){
				jQuery(this).parent().toggleClass("vmf_concept_closed")
			});
		}
	}
}

//-------------------------------------------------------------------------------------

jQuery(document).ready(function () {
    mylan.init();
});
