CABECERA = {
	inicio : function (){
		CABECERA.formularioIdentificacion();
		$("form#form_buscar").bind("submit", CABECERA.formularioBusqueda);
		CABECERA.lanzaFechaYHora();

		$("#piemediosmenu li a:eq(0)").hover(
			function() { $("#modulo1").show(); },
			function() { $("#modulo1").hide(); } );
		$("#modulo1").hover(
			function() { $(this).show()},
			function() { $(this).hide()} );
		$("#piemediosmenu li a:eq(1)").hover(
			function() { $("#modulo2").show(); },
			function() { $("#modulo2").hide(); } );
		$("#modulo2").hover(
			function() {$(this).show()},
			function() {$(this).hide()});
		/* Enlaces externos en ventana nueva */
		$("#piemenu a[rel=external]").attr("target", "_blank");
	},
	formularioIdentificacion : function (){
		if(($.cookie('login') == null) && ($.cookie('PlusLogNavegacion') != null)){
				strHtml = $.ajax({
						url: "/ajax/identificarcookie.html",
						async: false
			}).responseText;

		}
		if($.cookie('login') != null){
			$("div#noidentificado").hide();
			$("div#identificado").show();
			/* Decodificar y cortar el nombre si se pasa de largo */
			nombreUsuario = unescape($.cookie('login'));
			nombreUsuario = nombreUsuario.replace("+", " ");
			nombreUsuario = nombreUsuario.replace("%2B", "+");
			nombreUsuario = nombreUsuario.replace("%2F", "/");
			if (nombreUsuario.length > 12)
				nombreUsuario = nombreUsuario.substring(0, 9)+'...';

			$("span.nombre").append (nombreUsuario);
		}else{
			$("div#identificado").hide();
		}

	},
	formularioBusqueda : function () {
		oCajaBusqueda = this.pal;
		if (oCajaBusqueda.value == "") {
			alert ("Indique algo para buscar");
			oCajaBusqueda.focus();
			return false;
		}
	},
	timeoutID : null,
	this_month : new Array ("enero", "febrero", "marzo", "abril", "mayo", "junio", "julio", "agosto", "septiembre", "octubre", "noviembre", "diciembre"),
	this_day_e : new Array ("Domingo", "Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sábado"),
	lanzaFechaYHora : function () {
		/* Sincronizamos el cambio de fecha al cambio de minuto */
		CABECERA.fechaYHora();
		var fObj = new Date() ;
		iEspera = (60 - fObj.getSeconds())*1000;
		window.setTimeout("CABECERA.lanzaFechaYHoraCadaMinuto()", iEspera);
	},
	lanzaFechaYHoraCadaMinuto : function () {
		CABECERA.fechaYHora();
		CABECERA.timeoutID = window.setInterval("CABECERA.fechaYHora()", 60000);
	},
	fechaYHora : function() {
		var fecha = CABECERA.dameFecha();
		var hora = CABECERA.dameHora();
		$("#fecha").html(fecha+" - <span id=\"hora\">"+hora+"</span>");
	},
	dameFecha : function() {
		var today = new Date();
		var day   = today.getDate();
		var month = today.getMonth();
		var year  = today.getFullYear();
		var dia = today.getDay();

		return( " " + CABECERA.this_day_e[dia] + " " + day + " " + CABECERA.this_month[month] + " " + year);
	},
	dameHora : function () {
		var fObj = new Date() ;
		var horas = fObj.getHours() ;
		var minutos = fObj.getMinutes() ;

		if (horas <= 9) horas = "0" + horas;
		if (minutos <= 9) minutos = "0" + minutos;

		return horas+":"+minutos+" h";
	},

	muestraOtrosMedios : function() {
		/*alert(this);*/
		$("#modulo1").show();
		//return false;
	},

	ocultaOtrosMedios : function() {
		/*alert(this);*/
		$("#modulo1").hide();
		//return false;
	}
}
/* Soporte de javascript accesible desde el css */
/* añade a la etiqueta html un class="js" */
var isSupported = document.getElementById && document.getElementsByTagName;
if (isSupported) {
	sIdentificado = __getCookie("login") != null ? " ident " : " noident "; /* metemos espacios para separar las clases en el html */
	sAbonado= __getCookie("indAbonado") == "S" ? "abo" : "noabo";
	document.documentElement.className = "js"+sIdentificado+sAbonado;
}

$(document).ready(CABECERA.inicio);

function __setCookie(name, value, expires, path, domain, secure) {
	var curCookie = name + "=" + escape(value) +
	((expires) ? "; expires=" + expires : "") +
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "") +
	((secure) ? "; secure" : "");
	document.cookie = curCookie;
}

function __getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	} else
		begin += 2;
	var end = document.cookie.indexOf(";", begin);
	if (end == -1)
		end = dc.length;
	return unescape(dc.substring(begin + prefix.length, end));
}

if(__getCookie('plus_ctrl')==null)
{
	var d = new Date();
	__setCookie('plus_ctrl',d.getTime()+navigator.platform+navigator.appCodeName+screen.width,'Thu, 31 Dec 2008 23:59:59 UTC','/','plus.es');
}


/* Publicidad */
function playParamFlashObject(swfFile, id, dim, transparent, clsid, flashversion, divId)
{
	content = '<object classid="'+clsid+'" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+flashversion+',0,0,0" ID="'+id+'" '+dim+'>';
	if(swfFile.indexOf('?')!=-1){
		pos=swfFile.indexOf('?');
		fname=swfFile.substring(0,pos);
		fvars=swfFile.substring(pos+1,swfFile.length);
		content += '<param name="movie" value="'+fname+'" />';
		content += '<param name="FlashVars" value="'+fvars+'" />';
	}else{
		fname=swfFile;
		fvars='';
		content += '<param name="movie" value="'+fname+'" />';
	}
	content += '<param name="quality" value="high" /><param name="wmode" value="'+transparent+'" />';
	content += '<embed src="'+fname+'" FlashVars="'+fvars+'" quality="high" wmode="'+transparent+'" swLiveConnect="FALSE" '+dim+' name="'+id+'" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">';
	content += '</embed></object>';
	if (divId)
	{
		objDiv = document.getElementById(divId);
		objDiv.innerHTML=content;
	}
	else document.write(content);
	return content;
}
