/* DOMREADY *****************/
window.addEvent('domready', function() {
	cargarFondo();
});
/****************************/

function leerNoticia(id){
	var request = new Request({
		url: "include/leer_noticia.php",
		method: 'get',
		data: "id="+id,
		onRequest: function(){
			//$('preloader').fade('in');
			//$('preloader').getElement('img').src=$('preloader').getElement('img').src;
		},
		onComplete: function(response) {
			$('noticia').set('html',response);
			//$('preloader').slide('out');
			$('noticia').fade('in');
			//SqueezeBox.assign($$('a.boxed'));
			$$("#noticia a.lightbox").slimbox();
		}
	});
	
	var miEfecto = new Fx.Tween("noticia",{property: 'opacity'}).start(0).chain(function(){
		request.send();
	});
}

function mostrarEvento(lanzador,id){
	var div=$(id);
	var posx=findPos(lanzador,'x');
	var posy=findPos(lanzador,'y');
	div.style.left=posx+20+"px";
	div.style.top=posy-(div.offsetHeight/2)+"px";
	div.addClass('activo');
	//div.fade('hide');
	//div.fade('in');
}

function ocultarEvento(id){
	var div=$(id);
	div.removeClass('activo');
	//div.fade('out');
}

function findPos(obj,coordenada) {
	var curTop=0;
	var curLeft=0;
	if (obj.offsetParent) {
		curTop = obj.offsetTop;
		curLeft = obj.offsetLeft;
		while (obj = obj.offsetParent) {
			curTop += obj.offsetTop;
			curLeft += obj.offsetLeft;
		}
	}
	if(coordenada=="x"){ return curLeft; }
	else if(coordenada=="y"){ return curTop; }
	else{ return "0";}
}

var cantidad=1;
var maximos=7;//cambiar segun cantidad de fondos declarados
function cambiar(s){	
if(s=='s')cantidad++;
if(cantidad>maximos)cantidad=1;
switch(cantidad){
	case 1:
	     document.body.className='fondo1';
	break;
	case 2:
	     document.body.className='fondo2';
	break;
	case 3:
	     document.body.className='fondo3';
	break;
	case 4:
	      document.body.className='fondo4';
	break;
	case 5:
	      document.body.className='fondo5';
	break;
	case 6:
	     document.body.className='fondo6';
	break;
	case 7:
	     document.body.className='fondo7';
	break;
}
 setCookie ('mifondo', cantidad, 30);
}

function cargarFondo(){
	cantidad=parseInt(getCookie('mifondo'));
	cambiar('n');
}
 
 function caduca(dias) {  
    var hoy = new Date() ;                                        
    var msEnXDias = eval(dias) * 24 * 60 * 60 * 1000   ; 
    hoy.setTime(hoy.getTime() + msEnXDias) ;          
    return (hoy.toGMTString())  ;
} 
 
	///
	function setCookie(name, value, time)
         {
         //If name is the empty string, it places a ; at the beginning
         //of document.cookie, causing clearCookies() to malfunction.
		 if(!time)  
           time =0  ;
		   expires=caduca(time); 
         if(name != '')
            document.cookie = name + '=' + value  + '; expires=' + expires;
         }

function getCookie(name)
         {
         //Without this, it will return the first value 
         //in document.cookie when name is the empty string.
         if(name == '')
            return('');
         
         name_index = document.cookie.indexOf(name + '=');
         
         if(name_index == -1)
            return(1);
         
         cookie_value =  document.cookie.substr(name_index + name.length + 1, 
                                                document.cookie.length);
         
         //All cookie name-value pairs end with a semi-colon, except the last one.
         end_of_cookie = cookie_value.indexOf(';');
         if(end_of_cookie != -1)
            cookie_value = cookie_value.substr(0, end_of_cookie);

         //Restores all the blank spaces.
         space = cookie_value.indexOf('+');
         while(space != -1)
              { 
              cookie_value = cookie_value.substr(0, space) + ' ' + 
              cookie_value.substr(space + 1, cookie_value.length);
							 
              space = cookie_value.indexOf('+');
              }

         return(cookie_value);
         }

function clearCookie(name)
         {                  
         expires = new Date();
         expires.setYear(expires.getYear() - 1);

         document.cookie = name + '=null' + '; expires=' + expires; 		 
         }
         
function clearCookies()
         {
         Cookies = document.cookie;
         Cookie = Cookies;
         expires = new Date();
         expires.setYear(expires.getYear() - 1);

         while(Cookie.length > 0)
              {
              //All cookie name-value pairs end with a semi-colon, except the last one.
              Cookie = Cookies.substr(0, Cookies.indexOf(';'));
              Cookies = Cookies.substr(Cookies.indexOf(';') + 1, Cookies.length);

              if(Cookie != '')
                 document.cookie = Cookie + '; expires=' + expires;
              else
                 document.cookie = Cookies + '; expires=' + expires;			  			  	  
              }		 		 
         }