// JavaScript Document
clicked='bot1';
seccioanterior='divinicio';

// cross-browser add-remove event to object
EventManager =
{
	addEvent: function(obj, e, func)
	{
		//W3C, Mozilla
		if(obj.addEventListener)
		{
			obj.addEventListener(e, func, false);
		}
		//IE
		else if(obj.attachEvent)
		{
			obj.attachEvent("on"+e, func);
		}
		//others
		else
		{
			obj["on"+e] = func;
		}
	},
	
	removeEvent: function(obj, e, func)
	{
		if(obj.removeEventListener)
		{
			obj.removeEventListener(e, func, false);
		}
		else if(obj.detachEvent)
		{
			obj.detachEvent("on"+e, func);
		}
		else
		{
			obj["on"+e] = null;
		}
	},
	
	delegate: function(o, f, inherit_args)
	{
		var a = new Array();
		for(var i=3; i<arguments.length; i++) a.push(arguments[i]);
		return function()
		{
			//se envían además los parámetros propios que el método devuelve
			if(inherit_args)
			{
				var ar = new Array();
				for(var i=0; i<arguments.length; i++) ar.push(arguments[i]); //arguments no se considera una array, por lo que no funciona 'concat'
				f.apply(o, ar.concat(a)); //suma a los valores retornados por la funcion por defecto los definidos por el usuario
			}
			else
			{
				f.apply(o, a);
			}
		}
	}
};

//--------------------------------------------------------------------------

// Permuta una imagen cuyo nombre acabe en "_on." o "_off." (versión 2.1)
function commuteImg()
{
	var sSrc = this.src,
		rSearch = new RegExp("_(on|off)\\.");
	sSrc.match(rSearch);
	var sSrc = sSrc.replace("_"+RegExp.$1+".", "_"+((RegExp.$1=="off") ? "on" : "off")+".");
	this.src = sSrc;
}

function prepareChangeImages()
{
	var allImg = document.getElementsByTagName("IMG");
	for(var i=0; i<allImg.length; i++)
	{
		var oAttr = String(allImg[i].getAttribute("src"));
		if(oAttr.toLowerCase().match("_off."))
		{
			var o = allImg[i];
				o.onmouseover	= commuteImg;
				o.onmouseout	= commuteImg;
		}
	}
}

EventManager.addEvent(window, "load", prepareChangeImages);



//--------------------------------------------------------------------------




function init(){
	clicked=$('bot1');
	seccioanterior='seccion1';
	$('bot1').setStyle({ background:'url("../img/buttons.gif") 0 36px'});
	
}

function menuover(opcio){
	if(opcio!=clicked)$(opcio).setStyle({ background:'url("../img/buttons.gif") 0 72px' });
}
function menuout(opcio){
	if(opcio!=clicked)$(opcio).setStyle({ background:'url("../img/buttons.gif") 0 0'});
}

function menuclick(opcio){
	
	if(clicked!=opcio){
		var arrayclasses= $$('#topmenu DIV.menubutton');
		arrayclasses.each(function(item) {
   			item.setStyle({background:'url("../img/buttons.gif") 0 0'});
			
  		});
	
		opcioid=$(opcio).id;
	

		$(opcio).setStyle({background:'url("../img/buttons.gif") 0 36px'});
			
		
		$(seccioanterior).hide();
		
		switch(opcioid){
		
			case 'bot1':$('seccion1').show();seccioanterior='seccion1';break;
			case 'bot2':$('seccion2').show();seccioanterior='seccion2';break;
			case 'bot3':$('seccion3').show();seccioanterior='seccion3';break;
			case 'bot4':$('seccion4').show();seccioanterior='seccion4';break;
			case 'bot5':$('seccion5').show();seccioanterior='seccion5';break;
			case 'bot6':$('seccion6').show();seccioanterior='seccion6';break;
					
		}
		clicked=opcio;
	}
	
}

/*function gotoinit(){

	if(seccioanterior!='divinicio'){
		var arrayclasses= $$('#divmenu DIV.menubutton');
			arrayclasses.each(function(item) {
				item.setStyle({backgroundColor: '#f4f4f4', color:'#999999', backgroundImage:''});
				
			});
			
			$('bot1').setStyle({ color:'#FFFFFF',backgroundImage:'url("img/menu_init.gif")'});
			
			new Effect.Fade(seccioanterior,{duration: 0.8});
			new Effect.Appear('divinicio',{duration: 0.8,delay:0.8});
			seccioanterior='divinicio';
			clicked=$('bot1');
   }
}



function verdetalle(response){
	
	
	
	var json_vars=response.responseText;
	noticias = eval(json_vars);
	
	var arrayclasses= $$('#divmenu DIV.menubutton');
		arrayclasses.each(function(item) {
   			item.setStyle({backgroundColor: '#f4f4f4', color:'#999999', backgroundImage:''});
			
  		});
		
		$('bot3').setStyle({backgroundImage:'url("img/bot_over.gif")', color:'#FFFFFF'});
		
		

	new Effect.Fade(seccioanterior,{duration: 0.8});
	
	
	
	$('detalle_titular').update(noticias[0]);
	$('detalle_pie_img').update(noticias[1]);
	$('news_detalle_img').src="uploads/"+noticias[2];
	$('detalle_info').update(noticias[3]+" - "+noticias[4]);
	$('detalle_full').update(noticias[5]);
	
	
	
	new Effect.Appear('divdetalle1',{duration: 0.8,delay:0.8});
	seccioanterior='divdetalle1';
	
	clicked='';	

}

function opendetalle(opcio,lang){

		
		var url = 'getnoticia.php';
		var pars = 'id='+opcio+'&lang='+lang;
		var myAjax = new Ajax.Updater(
				{success: 'placeholder'}, 
				url, 
				{
					method: 'post',  
					parameters: pars,
					//onFailure: showError,
					onComplete: verdetalle
				});
	
}

function change_proceso(sec){

	if(sec==1){
		$('img_menu2').setStyle({display: 'none'});
		$('img_menu1').setStyle({display: 'block'});
		new Effect.Fade('procesos_content2',{duration: 0.8});
		new Effect.Appear('procesos_content1',{duration: 0.8,delay:0.8});
	}else{
		$('img_menu1').setStyle({display: 'none'});
		$('img_menu2').setStyle({display: 'block'});
		new Effect.Fade('procesos_content1',{duration: 0.8});
		new Effect.Appear('procesos_content2',{duration: 0.8,delay:0.8});
	
	}

}


function cambio_apartado(valor){


	if(valor==4){
		//estoy en una noticia y quiero volver
		new Effect.Fade(seccioanterior,{duration: 0.8});
		new Effect.Appear('divnoticias',{duration: 0.8,delay:0.8});
		seccioanterior='divnoticias';
	
	}else{
		//Estoy en un destacado de la home
		$('bot1').setStyle({color:'#999999', backgroundImage:''});
		
		new Effect.Fade('divinicio',{duration: 0.8});
		
		if(valor==1){
			$('bot5').setStyle({backgroundImage:'url("img/bot_over.gif")', color:'#FFFFFF'});
			new Effect.Appear('divaerosoles',{duration: 0.8,delay:0.8});
			seccioanterior='divaerosoles';
			clicked=$('bot5');
		
		}else if(valor==2){
			$('img_menu2').setStyle({display: 'none'});
			$('img_menu1').setStyle({display: 'block'});
			$('procesos_content1').setStyle({display: 'block'});
			$('procesos_content2').setStyle({display: 'none'});
			$('bot4').setStyle({backgroundImage:'url("img/bot_over.gif")', color:'#FFFFFF'});
			new Effect.Appear('divprocesos',{duration: 0.8,delay:0.8});
			seccioanterior='divprocesos';
			clicked=$('bot4');
		
		}else if(valor==3){
			$('img_menu1').setStyle({display: 'none'});
			$('img_menu2').setStyle({display: 'block'});
			$('procesos_content2').setStyle({display: 'block'});
			$('procesos_content1').setStyle({display: 'none'});
			$('bot4').setStyle({backgroundImage:'url("img/bot_over.gif")', color:'#FFFFFF'});
			new Effect.Appear('divprocesos',{duration: 0.8,delay:0.8});
			seccioanterior='divprocesos';
			clicked=$('bot4');
			
		}
	
	}



}
	
function open_map () {
       myLightWindow.activateWindow({
               href: 'http://www.cscbooksaver.com/map.html',
               width: 500,
               height: 300,
               title: '',
			   lightwindow_iframe_embed:true
       })
}
function change_over_video(capa){

	$(capa).setStyle({backgroundColor: '#c1c1c1'});

}

function change_out_video(capa){

	$(capa).setStyle({backgroundColor: '#e1e1e1'});

}

function open_video(numvideo){
	
	if(numvideo==1){
	
		myLightWindow.activateWindow({
				   href: 'videos/video1.swf',
				   width: 352,
				   height: 304,
				   iframeEmbed:true,
				   title: ''
				   
				   
		})

	}else if(numvideo==2){
		myLightWindow.activateWindow({
				   href: 'videos/video2.swf',
				   width: 352,
				   height: 327,
				   title: '',
				   iframeEmbed:true
				   
		})
	
	}else if(numvideo==3){
		myLightWindow.activateWindow({
				   href: 'videos/video3.swf',
				   width: 351,
				   height: 327,
				   title: '',
				   iframeEmbed:true
				   
		})
	
	}else if(numvideo==4){
		myLightWindow.activateWindow({
				   href: 'videos/video4.swf',
				   width: 352,
				   height: 327,
				   title: '',
				   iframeEmbed:true
				   
		})
	
	}else if(numvideo==5){
		myLightWindow.activateWindow({
				   href: 'videos/video5.swf',
				   width: 349,
				   height: 327,
				   iframeEmbed:true,
				   title: ''
				   
		})
	
	}
	
	
	
	
}*/