// JavaScript Document
window.addEvent('domready', function() 
{
	/**************************************************** MENU **************************************************/
		$$(".menu_li").each(function(Menuelemento){
								 					 
			Menuelemento.addEvents(
			{
				'mouseenter': function()
				{
					var submenu = Menuelemento.getFirst().getNext();
					if (submenu){
						Menuelemento.getFirst().setStyle('color', '#FFFFFF');
						submenu.setStyle('display', 'block'); //muestro el submenu

					}
				},
				'mouseleave': function()
				{
					var submenu = Menuelemento.getFirst().getNext();
					if (submenu){
						
						Menuelemento.getFirst().setStyle('color', '#C2C2C2');
						submenu.setStyle('display', 'none');
					}
				}
			});							
												
	});
		
	/**************************************************** MENU LI **************************************************/

			$$(".submenu_li a").each(function(submenuelemento){
														 
				submenuelemento.addEvents(
				{
					'mouseenter': function()
					{		
						submenuelemento.setStyle('text-indent', '0px'); //	text-indent: 5px;
	
					},
					'mouseleave': function()
					{
						submenuelemento.setStyle('text-indent', '0px'); //	text-indent: 5px;
					}
				});							
													
			});
	/**************************************************** CONTACTO **************************************************/

	/*
	$$('#contacto input', '#contacto textarea').each(function(inputEl)
	{
		if (inputEl.getProperty('class')!="form_button")
		{
			inputEl.addEvents(
			{
				'focus': function()
				{
					inputEl.setStyle('background', '#EAF5F9');
				},
				'blur': function()
				{
					inputEl.setStyle('background', '#FFFFFF');
				}
			});
		}
	});*/



}); //end  domload



/*************************************************** encuestas **************************************************/

function votarFn(){

	var contactoAjax = new Ajax('encuesta_post.php',
	{
		encoding:'iso-8859-1',
		method: 'post',
		data:$('encuesta'),
		update:$('update_container_encuesta'),
		evalScripts: true,
		onRequest: function()
		{
			$('update_container_encuesta').setHTML('<img src="imagenes/ajax-loader.gif" style="float:left; padding:0px 4px;"><span style="display:block; padding:4px 8px; color:red;">enviando datos...</span>');
		}
	});
	contactoAjax.request();
};


/*************************************************** table collapse **************************************************/

function table_minimizar(colapsable){
	
	
	var colapsado = $$(colapsable).getStyle('display');

	
	if (colapsado[0]=='none'){
		
		if (window.ie){
			$$(colapsable).setStyle('display', 'block'); //table-row
		}else
		{
			$$(colapsable).setStyle('display', 'table-row'); //table-row
		}
		$$(".vermas_tabla").setHTML("Minimizar panel [-]");
		var colapsado = false;
		
	}else{
		
		$$(colapsable).setStyle('display', 'none');
		$$(".vermas_tabla").setHTML("Ver más distancias [+]");
		var colapsado = true;

	}
	
}


function div_collapse(colapsable){
	
	
	var colapsado = $$(colapsable).getStyle('display');

	
	if (colapsado[0]=='none'){
		
		if (window.ie){
			$$(colapsable).setStyle('display', 'block'); //table-row
		}else
		{
			$$(colapsable).setStyle('display', 'table-row'); //table-row
		}
		$$(".vermas_tabla").setHTML("Minimizar [-]");
		var colapsado = false;
		
	}else{
		
		$$(colapsable).setStyle('display', 'none');
		$$(".vermas_tabla").setHTML("Ver más [+]");
		var colapsado = true;

	}
	
}

/*************************************************** POP UP **************************************************/

var popUpWin =0;
function popUpWindow(URLStr, left, top, width, height,scrollb)
{
  width = width + 40;
  height = height + 20;
  left = screen.width/2 - width/2
  top = screen.height/2 - height/2
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin= open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars='+scrollb+',resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

var popUpWin2 =0;
function popUpWindow2(URLStr, left, top, width, height)
{
  left = screen.width/2 - width/2
  top = screen.height/2 - height/2
  if(popUpWin2)
  {
    if(!popUpWin2.closed) popUpWin2.close();
  }
  popUpWin2 = open(URLStr, 'popUpWin2', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

/*************************************************** AGRANDAR TEXTO **************************************************/

var minsize=8;
var maxsize=18;
var deft=10;
var actual=13;

function MasTxt(div){
actual = actual+1;
if (actual > maxsize) {
actual = maxsize
}
var divID = document.getElementById(div);
divID.style.fontSize = actual+"px";
// px porque estoy usando css
}

function MenosTxt(div) {
actual = actual-1;
if (actual < minsize) {
actual = minsize
}
var divID = document.getElementById(div);
divID.style.fontSize = actual+"px";
}

/*************************************************** PRINT **************************************************/
function printPage() { print(document); }

/*************************************************** BOOKMARK **************************************************/
function agregar(){
   if ((navigator.appName=="Microsoft Internet Explorer") && (parseInt(navigator.appVersion)>=4)) {
      var url="http://www.TuSitio.com/";
      var titulo=" Descripcion de mi sitio web";
      window.external.AddFavorite(url,titulo);
   }
   else {
      if(navigator.appName == "Netscape")
         alert ("Presione Crtl+D para agregar este sitio en sus Bookmarks");
   }
} 


/*************************************************** BLINK **************************************************/
/*

	var opciones = {
		'property' : 'color',
		'from' : new Color('#fff'),
		'to' : new Color('#f00'),
		'endActive' : false,
		'times':80,
		'duration' : 300
	};

	var els = new blinkProperty('DIV ID',opciones);
	els.doIt();

*/


var blinkProperty = new Class({
	opciones : {},
	element : null,

	initialize : function(el, opciones) {
		this.opciones = Object.extend({
			'property' : 'border-color',
			'duration' : 500,
			'margin' : 50,
			'from' : new Color('#000'),
			'to' : new Color('#fff'),
			'times' : 3,
			'transition' : Fx.Transitions.linear,
			'endActive' : true
		}, opciones || {});

		this.element = el;
	},

	doIt : function() {
		var blink = new Fx.Style(this.element, this.opciones['property'], {'duration': this.opciones['duration'], 'transition': this.opciones['transition']});
		blink.start(this.opciones['from'], this.opciones['to']);
		for(var i = 0; i < this.opciones['times']; i++) {
			blink.start.pass([this.opciones['to'], this.opciones['from']], blink).delay((this.opciones['duration']+this.opciones['margin']) * ((i*2)+1));
			blink.start.pass([this.opciones['from'], this.opciones['to']], blink).delay((this.opciones['duration']+this.opciones['margin']) * ((i*2)+2));
		}
		if(!this.opciones['endActive'])
			blink.start.pass([this.opciones['to'], this.opciones['from']], blink).delay((this.opciones['duration']+this.opciones['margin']) * ((i*2)+1));
	}
});

/*************************************************** LIGHTBOX **************************************************/
function lightbox(url,boxX,boxY){
	

	var alturaTotal = window.getScrollHeight();
	
	
	//creo el box
	var tamW = window.getSize();	
	//var tamE = $('Lightbox_Container').getSize();
	
	if(window.ie6){
		var valposition = "absolute";
		var posX = (tamW.size.x/2 - boxX/2) + tamW.scroll.x;
		var posY = (tamW.size.y/2 - boxY/2) + tamW.scroll.y;
		var width = tamW.size.x+'px';
	}else if(window.opera){
		var valposition = "fixed";
		var posX = (tamW.size.x/2 - boxX/2);
		var posY = (window.innerHeight/2 - boxY/2);
		var width = "100%";
	}else{
		var valposition = "fixed";
		var posX = (tamW.size.x/2 - boxX/2);
		var posY = (tamW.size.y/2 - boxY/2);
		var width = "100%";
	}

	
	//fondo opaco
	var div_bg = new Element('div',
	{
		  'id':'light_box_bg',
		  'styles':
		  {
				'position':'absolute',
				'top':'0px',
				'left':'0px',
				'display':'block',
				'width':width,
				'height':alturaTotal+'px',
				'z-index':'99990'
		  }
	});
	div_bg.injectAfter('subbody');
	

	var misEfectos = new Fx.Styles('light_box_bg');
	misEfectos.start(
	{
		'background-color':['#FFFFFF','#000000'],
		'opacity': [0, 0.8]
	});

	
	



	var div_box_container = new Element('div',
	{
		  'id':'Lightbox_Container',
		  'styles':
		  {
				'position': valposition,
				'top':posY+'px',
				'left':posX+'px',
				'width':boxX,
				'height':boxY,
				'z-index':'999991'
		  }
	});
	


	div_box_container.injectAfter('light_box_bg');
	
	//$('Lightbox_Container').makeDraggable();


	var miAjax = new Ajax(url,
	{
		method: 'get',
		encoding:'iso-8859-1',
		update:$('Lightbox_Container'),
		evalScripts: true
	});
	miAjax.request();
	
	
	//cerrar el lightbox
	$('light_box_bg').addEvent('click', function()
	{
		$('Lightbox_Container').remove();
		$('light_box_bg').remove();
	});




}

function light_box_cerrar(){

		$('Lightbox_Container').remove();
		$('light_box_bg').remove();
	
}

/*************************************************** CENTRA ELEMENTOS **************************************************/
function centra_elementos(elemento, OffsetX,OffsetY){
	
	//obtengo del elemento
	var element_size = elemento.getSize();
	var boxY = element_size['size']['y']
	var boxX = element_size['size']['x']
	
	
	//creo el box
	var tamW = window.getSize();	
	
	if(window.ie6){
		var valposition = "absolute";
		var posX = (tamW.size.x/2 - boxX/2) + tamW.scroll.x;
		var posY = (tamW.size.y/2 - boxY/2) + tamW.scroll.y;

	}else{
		var valposition = "fixed";
		var posX = (tamW.size.x/2 - boxX/2);
		var posY = (tamW.size.y/2 - boxY/2);
	}
	
	
	elemento.setStyles(
	{
		 'position': valposition,
		 'top': posY+OffsetY,
		 'left': posX+OffsetX
	});
	
}

/*************************************************** CENTRA ELEMENTOS **************************************************/
function LoginAccess(){

	var LogginAjax = new Ajax('prensa_login_post.php',
	{
		encoding:'iso-8859-1',
		method: 'post',
		data:$('login_container'),
		update:$('update_container'),
		evalScripts: true,
		onRequest: function()
		{
			$('update_container').setHTML('<img src="imagenes/ajax-loader.gif" style="float:left; padding:0px 4px;"><span style="display:block; padding:4px 8px; color:red;">Enviando datos...</span>');
		}
	});
	LogginAjax.request();
};


