var array_de_videos= new Array();

jQuery(document).ready(function(){
	var inner='<div style="padding:10px 0 0 20px;float:left;"><h1 id="titulazo"></h1></div><div style="float:right;padding:10px 20px 0 0;"><h1 id="lideres_otton">Líderes con OTTON</h1></div><div style="clear:both;"></div><div id="carga_video"><img src="ajax-loader.gif" /></div><div id="lista_maes"><ul></ul></div><div id="info_mae"></div>';
	jQuery("#m-Lideres").bind('click',function(){jQuery("#oscuridad").fadeIn("slow",function(){jQuery(document.createElement('div')).attr({"id":"vvde"}).css({'position':'absolute','display':'none','width':'800px','height':"600px",'background':'#FFF','top':'20px','left':((jQuery(window).width()/2)-400)}).appendTo('body').html(inner).fadeIn('slow',function(){																																																																																																															   jQuery.getJSON("lista_lideres.php",function(data){																																																																																																																										   		jQuery.each(data.items,function(i,item){
			if(i==0){
				jQuery("#carga_video").html(item.video);
				jQuery("#titulazo").html(item.titulo);
				jQuery("#info_mae").html(item.texto);
			}
			jQuery(document.createElement('li')).appendTo("#lista_maes ul:first").html('<a href="javascript:;" rel="l-'+item.id+'" style="text-decoration:none;" onclick="cargaVid(this.rel)">'+item.titulo+'</a>');
		});
	})})}).bind('click',function(){jQuery("#vvde").remove();jQuery("#oscuridad").css('display','none');});return false;});
});

function cargaVid(id) {
	jQuery("#carga_video").html("<img src=\"ajax-loader.gif\">");
	jQuery.getJSON("lista_lideres.php?vid="+id.split("-")[1],function(data){
		jQuery("#carga_video").html(data.video);
		jQuery("#titulazo").html(data.titulo);
		jQuery("#info_mae").html(data.texto);
	});
}


function abrir_popup(url){
		a=window.open("http://otton.cr/suscripcion/?p=subscribe&id=1","Suscripción","toolbar=0,menubar=0,status=1,width=600, resizable=no");		
	};


	jQuery(document).ready(function(){
		intervalo = setInterval(cambiarNoti,4000);		
		jQuery('#noticias .notis a').bind("mouseenter",function(){clearInterval(intervalo)});
		jQuery('#noticias .notis a').bind("mouseleave",function(){intervalo=setInterval(cambiarNoti,3000)});
	});
	
	
	
	function cambiarNoti() {
		div = jQuery('#noticias .notis a:visible');
		if (div.next().html()) {
			div.fadeOut('slow',function(){div.next().fadeIn('slow')});
		}
		else {
			div.fadeOut('slow',function(){jQuery('#noticias .notis a:first-child').fadeIn('slow')});
		}		
	}
	
	
	var yyy;
	function abrirLink(url,event){
		var div=jQuery("#link_compartir");
		div.fadeIn('slow');
		div.html("<div style=\"background:url(images/triangulo.gif) right bottom no-repeat; heigth:20px; width:280px\">&nbsp;</div><div style=\"background:#C21638;height:100px;width:290px;\"><div class=\"amarilloE\" style=\"padding:10px;float:left;width:220px\"><a href=\"javascript:void(0)\" onclick=\"copy_clip('http://www.otton.cr/"+url+"')\">Copia</a> y pega el link para compartir el art&iacute;culo</div><div id=\"x\" style=\"float:right;width:20px;margin-top:5px;margin-right:5px;\"><img src=\"http://otton.cr/images/x.gif\" onclick=\"cerrarbyid('link_compartir')\" onmouseover=\"this.style.cursor='pointer'\" height=\"13\" width=\"13\"></div><div style=\"padding:10px\"><input id=\"parasel\" style=\"margin-top:10px;border:none;width:100%;background:#FFF;\" value=\"http://www.otton.cr/"+url+"\" onclick=\"this.focus();this.select==true ? this.select=false : this.select=true\" onblur=\"this.select=false\"></input></div></div>");
		div.css("top",event.clientY+5);
		div.css("left",event.clientX-280);
		div.css("height","100px");
		div.css("width","290px");
		jQuery("#parasel").focus();
		jQuery("#parasel").select();
	}
	
	function cerrarbyid(link) {
		jQuery('#'+link).fadeOut('slow',function() {jQuery('#'+link).html('')});
	}
	
	var bbb=function closeThis() {		
		jQuery("#link_compartir").fadeOut('slow',function() {jQuery("#link_compartir").html("")});
	}
	
	function hacer() {
		yyy=setTimeout(bbb,1000);
	}

function copy_clip(content) {

   
}
	
	
	function cerrar_com() {
		jQuery("#oscuridad").fadeOut('slow');
		jQuery("#fb_comentarios").css("display","none");
		jQuery("#laX").css("display","none");
		jQuery("#comentar").html('');
	}

	function showComments(url) {
	jQuery("#oscuridad").fadeIn('slow');
	jQuery("#fb_comentarios").css("display","block");
	jQuery("#laX").css("display","block");
	//jQuery('<iframe src="frame_comentario.php?id=15"></iframe>').insertAfter("#fb_comentarios");
	//jQuery("#comentar").load(url);
	jQuery.ajax({
			 	url: url,
				async: true,
				dataType: "html",
				success: function(datos){
					//jQuery("#scrollbar").css("visibility","hidden");
					//jQuery(document.location).attr('href', 'http://www.'+jQuery(document.location).attr('href').split('//')[1]);
					jQuery("#comentar").html(datos);
				},
				type: "GET"
		});
}



	function funcion_de_enviar(form,divBf,divAf) {
		
            // definimos las opciones del plugin AJAX FORM
            var opciones= {
                               beforeSubmit: mostrarLoader, //funcion que se ejecuta antes de enviar el form
                               success: mostrarRespuesta //funcion que se ejecuta una vez enviado el formulario
							   
            };
             //asignamos el plugin ajaxForm al formulario myForm y le pasamos las opciones
            jQuery('#'+form).ajaxForm(opciones) ; 
            
             //lugar donde defino las funciones que utilizo dentro de "opciones"
             function mostrarLoader(){
                      jQuery("#"+divBf).fadeIn("slow");
             };
             function mostrarRespuesta (){
                          jQuery("#"+divBf).fadeOut("slow");
						  jQuery('#'+form).css("display", "none");
						  jQuery("#"+divAf).css("display", "block");
						  
             };
	}
		
	function makeScrollbar(content,scrollbar,handle,horizontal,ignoreMouse){
	var steps = (horizontal?(content.getScrollSize().x - content.getSize().x):(content.getScrollSize().y - content.getSize().y))
	var slider = new Slider(scrollbar, handle, {	
		steps: steps,
		mode: (horizontal?'horizontal':'vertical'),
		onChange: function(step){
			// Scrolls the content element in x or y direction.
			var x = (horizontal?step:0);
			var y = (horizontal?0:step);
			content.scrollTo(x,y);
		}
	}).set(0);
	if( !(ignoreMouse) ){
		// Scroll the content element when the mousewheel is used within the 
		// content or the scrollbar element.
		$$(content, scrollbar).addEvent('mousewheel', function(e){	
			e = new Event(e).stop();
			var step = slider.step - e.wheel * 30;	
			slider.set(step);					
		});
	}
	// Stops the handle dragging process when the mouse leaves the document body.
	$(document.body).addEvent('mouseleave',function(){slider.drag.stop()});
}

function makeScrollbar(content,scrollbar,handle,horizontal,ignoreMouse){
				var steps = (horizontal?(content.getScrollSize().x - content.getSize().x):(content.getScrollSize().y - content.getSize().y))
				var slider = new Slider(scrollbar, handle, {	
					steps: steps,
					mode: (horizontal?'horizontal':'vertical'),
					onChange: function(step){
						// Scrolls the content element in x or y direction.
						var x = (horizontal?step:0);
						var y = (horizontal?0:step);
						content.scrollTo(x,y);
					}
				}).set(0);
				if( !(ignoreMouse) ){
					// Scroll the content element when the mousewheel is used within the 
					// content or the scrollbar element.
					$$(content, scrollbar).addEvent('mousewheel', function(e){	
						e = new Event(e).stop();
						var step = slider.step - e.wheel * 30;	
						slider.set(step);					
					});
				}
				// Stops the handle dragging process when the mouse leaves the document body.
				$(document.body).addEvent('mouseleave',function(){slider.drag.stop()});
			}
						
			window.addEvent('domready', function(){				
				
			});
			
//-------------------AJAX--------------------------

//pedido de ajax con jquery, si se da carga el contenido y lo hace en columnas
function getDataServer(url){

		if ((url.indexOf("agenda")==0)||(url.indexOf("encuentros")==0)) {
					jQuery("#target").css("position","absolute");
					jQuery("#target").css("width","700px");			
		}
		else {
			jQuery("#target").css("position","");
			jQuery("#target").css("width","1000px");
			jQuery("#target").css("display","block");
		}
		
	if ((url.indexOf("prensa_items")==-1) && (url.indexOf('info.php')==-1 && (url.indexOf('propuesta_items')==-1))) {
	url = url.replace("@","?");
			jQuery("#PagH1 a").removeClass('rojoE');
			jQuery('#m-'+url.split('=')[1]).addClass('rojoE');
		//if (url.indexOf("prensa_items")==-1) {
     	jQuery.ajax({
			 	url: url,
				async: true,
				dataType: "html",
				success: function(datos){				
				if ((url.indexOf("noticias")==-1)&&(url.indexOf("prensa_items")==-1)&&(url.indexOf("agenda")==-1)&&(url.indexOf("contacto")==-1)&&(url.indexOf("unete")==-1)&&(url.indexOf("propuesta")==-1)&&(url.indexOf("videos")==-1) && (url.indexOf("descargas")==-1) && (url.indexOf("sala_prensa")==-1) && (url.indexOf("campanha")==-1)&& (url.indexOf("blog")==-1)&&(url.indexOf("vida")) && (url.indexOf('encuentros')) && (url.indexOf("rumores"))) {
					jQuery("#target").css("width","1000px");
					jQuery("#carga").html(datos);
					jQuery(function(){
					jQuery("#carga").columnize({
						target: "#target",
						width:325,
						height:390
					});				
				});
				makeScrollbar( $('content'), $('scrollbar'), $('handle'), true );
				jQuery("#scrollbar").css("visibility","visible");
				} else {
					jQuery("#target").html("");
					jQuery("#scrollbar").css("visibility","hidden");
					jQuery("#target").css("width","1000px");
					//document.getElementById("target").style.background='#FF3388';
					jQuery("#target").html(datos);
					makeScrollbar( $('content'), $('scrollbar'), $('handle'), true );
				}
				},
				type: "GET"
		});
	}
	else {
		
		if (url.indexOf('si=1')==1) {
		jQuery.ajax({
			 	url: "noticias.php",
				async: true,
				dataType: "html",
				success: function(datos){				
					jQuery("#scrollbar").css("visibility","hidden");
					jQuery("#target").html(datos);
				},
				type: "GET"
		});
		
		}		
		else {			
			pet_prensa(url,2);
		}
		
		
		
	}
}

function getInfo(url,si) {
var url2 = url.replace('@','?');
url2 = url2.substring(1,url2.length);
jQuery("#crt").html("<img src=\"http://otton.cr/ajax-loader.gif\">");
	jQuery.ajax({
			 	url: url2,
				async: true,
				dataType: "html",
				success: function(datos){				
					jQuery("#relleno").html(datos);					
					jQuery(function(){
					if (datos.length!=7){
		jQuery("#relleno").columnize({				
			target: "#crt",
			width:300,
			height:390
		});
		makeScrollbar( $('content2'), $('scrollbar_peq'), $('handle2'), true );
		jQuery("#scrollbar_peq").css("visibility","visible");
		}
		else {
			jQuery("#crt").html("");
			jQuery("#scrollbar_peq").remove();
		}	 
});					
				},
				type: "GET"
		});
		
}

function peticion(url){
	if ((url.indexOf("prensa_items")==-1) && (url.indexOf("info.php")==-1) && url.indexOf("propuesta_items.php")==-1) {
	jQuery("#target").html("<div id=\"ajax_load\"><img src=\"http://otton.cr/ajax-loader.gif\"></div>");
	}
	getDataServer(url);
	var cadenaTexto = url;
	var fragmentoTexto = cadenaTexto.split('=');
	jQuery(document).attr('title', fragmentoTexto[1]+' | Ottón | La Costa Rica que queremos...');
}

function pet_prensa(url,si) {
	var url2 = url.replace('@','?');
	url2=url2.substring(1,url2.length);
	jQuery("#crt").html("");
	jQuery("#scrollbar_peq").css("visibility","hidden");
	
	jQuery("#cargar_not").html("<img src=\"http://otton.cr/ajax-loader.gif\">");
	jQuery.ajax({
			 	url: url2,
				async: true,//revisar
				dataType: "html",
				success: function(datos){
					jQuery("#cargar_not").html(datos);
					jQuery("#crt").html("");
				},
				type: "GET"
		});	
	/*}
	if (si==1){
		jQuery.historyLoad(url2.replace("?","@"));
	}*/
}

function pet_descarga(url,si) {
	var url2 = url.replace('@','?');
	url2 = url2.substring(1,url2.length);
	jQuery("#cargar_descarga").html("");
	jQuery("#item").html("");
	jQuery("#cargar_not").html("<img src=\"http://otton.cr/ajax-loader.gif\">");
	jQuery.ajax({
			 	url: url2,
				async: true,//revisar
				dataType: "html",
				success: function(datos){
					jQuery("#cargar_not").html(datos);
				},
				type: "GET"
		});	
	/*}
	if (si==1){
		jQuery.historyLoad(url2.replace("?","@"));
	}*/
}

function itemDescarga(url,si) {
	var url2 = url.replace('@','?');
	url2 = url2.substring(1,url2.length);
	jQuery("#item").html("cargando...");
	jQuery.ajax({
			 	url: url2,
				async: true,//revisar
				dataType: "html",
				success: function(datos){										
					jQuery("#item").html(datos);				

				},
				type: "GET"
		});
}

function getDescargas(url,si){
	var url2 = url.replace('@','?');
	url2 = url2.substring(1,url2.length);
	jQuery("#item").html("");
	jQuery("#cargar_descarga").html("cargando...");
	jQuery.ajax({
			 	url: url2,
				async: true,//revisar
				dataType: "html",
				success: function(datos){										
					jQuery("#cargar_descarga").html(datos);				

				},
				type: "GET"
		});	
	
}

function getPro(url,si) {
	var url2 = url.replace('@','?');
	url2 = url2.substring(1,url2.length);
	jQuery("#crt").html("cargando...");
	jQuery.ajax({
			 	url: url2,
				async: true,//revisar
				dataType: "html",
				success: function(datos){										
					jQuery("#relleno").html(datos);
					jQuery("#relleno").columnize({				
			target: "#crt",
			width:400,
			height:400
		});
					jQuery("#scrollbar_med").css("visibility","visible");
					makeScrollbar( $('content3'), $('scrollbar_med'), $('handle3'), true );

				},
				type: "GET"
		});	
	
}

function avanzar(url) {
	jQuery("#target").html("<div id=\"ajax_load\"><img src=\"http://otton.cr/ajax-loader.gif\"></div>");
	jQuery.ajax({
			 	url: url,
				async: true,//revisar
				dataType: "html",
				success: function(datos){										
					jQuery("#target").html(datos);
					//makeScrollbar( $('DosColumnasLibres'), $('scrollbar_med'), $('handle3'), true );

				},
				type: "GET"
		});	
}

function pageload(hash) {
		 // hash doesn't contain the first # character.
		if(hash) {
			// restore ajax loaded state
			//if (hash.indexOf("prensa_items")==-1)
			if (hash!='')			
			peticion(hash);					
		} else {
			jQuery('#target').html('');
			jQuery('#carga').html('');
			jQuery('#scrollbar').css("visibility","hidden");
			// start page
			//peticion(hash);//default de la primera pagina
		}
	}

	jQuery(document).ready(function(){	
		// Initialize history plugin.
		// The callback is called at once by present location.hash.
		jQuery.historyInit(pageload, "otton.php");		
		var hash ="";
				// set onlick event for buttons
		jQuery("a[rel='history']").click(function(){			
		hash = this.href.replace('?','@').split("/")[3];//cambio el ? por @ porque no pasa ?
		jQuery("#PagH, a").removeClass("rojoE");
		jQuery("#"+this.id).addClass("rojoE");
		jQuery("#video_ini").html('');
		jQuery('#noticias').remove();
		hash=hash.substring(1,hash.length);
		//var hash = this.href;
			//hash = hash.replace(/^.*#/, '');
			// moves to a new page. 
			// pageload is called at once. 
			// hash don't contain "#", "?"			
			jQuery.historyLoad(hash);
			return false;
		});
	});


function getVideos (url,si) {
	var url2 = url.replace('@','?');
	url2 = url2.substr(1,url2.length);
	jQuery("#DosColumnasLibres").html("");
	jQuery("#cargar_video").html("<img src=\"http://otton.cr/ajax-loader.gif\">");
	jQuery.ajax({
			 	url: url2,
				async: true,//revisar
				dataType: "html",
				success: function(datos){					
					jQuery("#DosColumnasLibres").html("");
					jQuery("#cargar_video").html(datos);
					//makeScrollbar( $('DosColumnasLibres'), $('scrollbar_med'), $('handle3'), true );
				},
				type: "GET"
		});	
}

function getVid (url,si) {
	var url2 = url.replace('@','?');
	url2 = url2.substring(1,url2.length);
	jQuery("#DosColumnasLibres").html("<img src=\"http://otton.cr/ajax-loader.gif\">");
	jQuery.ajax({
			 	url: url2,
				async: true,//revisar
				dataType: "html",
				success: function(datos){									
					jQuery("#DosColumnasLibres").html(datos);
					jQuery("#target").css("position","absolute");				
					//makeScrollbar( $('DosColumnasLibres'), $('scrollbar_med'), $('handle3'), true );

				},
				type: "GET"
		});	
}

//funcion para hacer la vara en columnas

/*
$('#timeline')
  .bind('mousedown', function(e) {
    // aquí vendrá nuestro código
  });
  
  $(document)
  .data('timeline', {
    element: this,
    scroll: this.scrollLeft,
    x : e.clientX
  });*/
var a= function func (){
	var mousePositions = document.getElementById('mousePositions');
	mousePositions.style.top = y+'px';
}

function position(x,y){
	/*mousePositions.innerHTML = 'X coords: '+x+', Y coords: '+y;*/
	jQuery("#mousePositions").html("");
	jQuery("#mousePositions").css("display",'block');
	jQuery("#mousePositions").css("left",  x+'px');
	jQuery("#mousePositions").css("top", y+'px');
}
var aaa;
function cerrar(id){
	 aaa = setTimeout(cer, 700);
}

var cer = function cerrar2(id){

var div = document.getElementById('mousePositions');
div.style.display = 'none';
}

function cerrar3(){
var mousePositions = document.getElementById('mousePositions');
mousePositions.style.display = 'none';
}


function cerrar4(){
var mousePositions = document.getElementById('formulario');
mousePositions.style.display = 'none';
}

function cargarEventos(event,fecha){
	jQuery("#contenidoCal").html("Cargando...");
	jQuery("#mousePositions").fadeIn("slow");
	jQuery("#mousePositions").css("left",  event.clientX+'px');
	jQuery("#mousePositions").css("top", event.clientY+'px');
jQuery.ajax({
			 	url: "consultas_agenda.php?fecha="+fecha,
				async: true,
				dataType: "html",
				success: function(datos){				
					/*jQuery("#scrollbar").css("display","none");*/
					jQuery("#contenidoCal").html(datos);
				},
				type: "GET"
		});
		}
		
function cargarEventos2(event,fecha){
	jQuery("#contenidoCal").html("Cargando...");
	jQuery("#mousePositions").fadeIn("slow");
	jQuery("#mousePositions").css("left",  event.clientX+'px');
	jQuery("#mousePositions").css("top", event.clientY+'px');
jQuery.ajax({
			 	url: "consultas_agenda2.php?fecha="+fecha,
				async: true,
				dataType: "html",
				success: function(datos){				
					/*jQuery("#scrollbar").css("display","none");*/
					jQuery("#contenidoCal").html(datos);
				},
				type: "GET"
		});
		}
				
function cargarFormulario(event, pagina){
	jQuery("#formulario").html("Cargando Formulario...");
	jQuery("#formulario").css("display",'block');
	jQuery("#formulario").css("left",  event.clientX+'px');
	jQuery("#formulario").css("top", event.clientY+'px');
jQuery.ajax({
			 	url: pagina,
				async: true,
				dataType: "html",
				success: function(datos){				
					/*jQuery("#scrollbar").css("display","none");*/
					jQuery("#formulario").html(datos);
				},
				type: "GET"
		});
		}
		
function valor(campo){
//alert('ghkljdklñ');
window.document.getElementById(campo).value = '';
}

function valor2(campo){
//alert('ghkljdklñ');
window.document.getElementById(campo).value = 'E-mail';
}