// JavaScript Document
jQuery(function( $ ){

	$(document).ready(function(){
		var first = 0;
		var speed = 500;
		var pause = 5000;
			function removeFirst(){	
				first = $('ul#listticker li:first').html();
				var seleccionado = $('ul#listticker li:first').attr("class");
				$('ul#listticker li:first')
				.animate({opacity: 0}, speed) 			
				.slideUp(100)
				.fadeOut('slow', function() {$(this).remove();});
				addLast(first,seleccionado);
			}
			function addLast(first,seleccionado){
				last = '<li style="display:none" class="'+seleccionado+'">'+first+'</li>';
				$('ul#listticker').append(last)
				$('ul#listticker li:last')
				.animate({opacity: 1}, speed)
				.fadeIn('slow')
			}
		interval = setInterval(removeFirst, pause);
	});

	$(document).ready(function(){
		var firstw = 0;
		var speedw = 1000;
		var pausew = 5000;
			function removeFirstw(){	
				firstw = $('ul#listticker2 li:first').html();
				var seleccionados = $('ul#listticker2 li:first').attr("class");
				$('ul#listticker2 li:first')
				.animate({opacity: 0}, speedw) 			
				.slideUp(100)
				.fadeOut('slow', function() {$(this).remove();});
				addLastw(firstw,seleccionados);
			}
			function addLastw(firstw,seleccionados){
				lastw = '<li style="display:none" class="'+seleccionados+'">'+firstw+'</li>';
				$('ul#listticker2').append(lastw)
				$('ul#listticker2 li:last')
				.animate({opacity: 1}, speedw)
				.fadeIn('slow')
			}
		interval = setInterval(removeFirstw, pausew);
	});
	
	$(document).ready(function() {
		//$('.navbarli li:last-child').css({'border' : '0px none'});	
		$("img").load(function() {
			$("ul.gallery li").each(function () {
				var vari = $(this).find("img").width();
				$(this).find("span").css({'width' : vari+'px'});
				$(this).find("a.thumb").css({'width' : vari+'px'});			
			});	
			$("ul.gallery li").hover(function() { //En hover...		
				var thumbOver = $(this).find("img").attr("src"); //Obtener la direccion de la imagen y asiganarla a 'thumbOver'		
				//Definir una imagen de fondo (thumbOver) en la etiqueta <a> - Definir la posicion en la parte inferior (bottom)		
				$(this).find("a.thumb").css({'background' : 'url(' + thumbOver + ') no-repeat 0px -60px'});		
				//Animar la imagen a opacidad 0 (fade out)		
				$(this).find("span").stop().animate({opacity: 0}, 300);		
				} , function() { //on hover out...		
				//Animar la imagen a opacidad 100% (fade in)		
				$(this).find("span").stop().animate({opacity: 1}, 300);		
			});
		});
	
	});
	

	$(document).ready(function() {	
/*							  
		lastBlock = $("#a1");
		maxWidth = 160;
		minWidth = 65;	
		$("#u1 li a").hover(
		  function(){
			$(lastBlock).animate({width: minWidth+"px"}, { queue:false, duration:400 });
			$(this).animate({width: "auto"}, { queue:false, duration:400});
			lastBlock = this;
		  }
		);	
		lastBlock2 = $("#a2");
		$("#u2 li a").hover(
		  function(){
			$(lastBlock2).animate({width: minWidth+"px"}, { queue:false, duration:400 });
			$(this).animate({width: "auto"}, { queue:false, duration:400});
			lastBlock2 = this;
		  }
		);
		lastBlock3 = $("#a3");
		$("#u3 li a").hover(
		  function(){
			$(lastBlock3).animate({width: minWidth+"px"}, { queue:false, duration:400 });
			$(this).animate({width: "auto"}, { queue:false, duration:400});
			lastBlock3 = this;
		  }
		);
		lastBlock4 = $("#a4");
		$("#u4 li a").hover(
		  function(){
			$(lastBlock4).animate({width: minWidth+"px"}, { queue:false, duration:400 });
			$(this).animate({width: "auto"}, { queue:false, duration:400});
			lastBlock4 = this;
		  }
		);
		lastBlock5 = $("#a5");
		$("#u5 li a").hover(
		  function(){
			$(lastBlock5).animate({width: minWidth+"px"}, { queue:false, duration:400 });
			$(this).animate({width: "auto"}, { queue:false, duration:400});
			lastBlock5 = this;
		  }
		);
		lastBlock6 = $("#a6");
		$("#u6 li a").hover(
		  function(){
			$(lastBlock6).animate({width: minWidth+"px"}, { queue:false, duration:400 });
			$(this).animate({width: "auto"}, { queue:false, duration:400});
			lastBlock6 = this;
		  }
		);
		lastBlock7 = $("#a7");
		$("#u7 li a").hover(
		  function(){
			$(lastBlock7).animate({width: minWidth+"px"}, { queue:false, duration:400 });
			$(this).animate({width: "auto"}, { queue:false, duration:400});
			lastBlock7 = this;
		  }
		);
		lastBlock8 = $("#a8");
		$("#u8 li a").hover(
		  function(){
			$(lastBlock8).animate({width: minWidth+"px"}, { queue:false, duration:400 });
			$(this).animate({width: "auto"}, { queue:false, duration:400});
			lastBlock8 = this;
		  }
		);	
		lastBlock9 = $("#a9");
		$("#u9 li a").hover(
		  function(){
			$(lastBlock9).animate({width: minWidth+"px"}, { queue:false, duration:400 });
			$(this).animate({width: "auto"}, { queue:false, duration:400});
			lastBlock9 = this;
		  }
		);
		*/                        
		if($('#cohis').length>0){
			$('div[id^="c"]').hide();
			$('#cohis').show();
		}

		if($('#co10').length>0){
			
			/*if($('form').length>0){
			}
			else{*/
				$('div[id^="c"]').hide();
				$('#co10').show();
			/*}*/
		}


		$('a[rel^="o"]').click(function(){                        
			if ($(this).attr("class")=='selected'){
					return false;				
			}
			else{
				var seleccionado = $(this).attr("rel");

				if(/*(seleccionado=='o4')||*/(seleccionado=='o5')){
					}
				else{                                          
                                        if(seleccionado == 'o1')
                                        {                                        
                                          $('#fondeados').html('<p align="center"><img src="img/ajax-loader-two.gif"/></p>');                                                
                                          $('#fondeados').load("fondeados.jsp");
                                        }else
                                          if(seleccionado == 'o2')
                                          {
                                            $('#atracados').html('<p align="center"><img src="img/ajax-loader-two.gif"/></p>');                                                
                                            $('#atracados').load("atracados.jsp"); 
                                          }else
                                            if(seleccionado == 'o3')
                                            {                                              
                                              $('#buquescierre').html('<p align="center"><img src="img/ajax-loader-two.gif"/></p>');  
                                              $('#buquescierre').load("cierre.jsp");                                             
                                            }else
                                              if(seleccionado == 'o4')
                                              {                                              
                                                $('#notificacionrec').html('<p align="center"><img src="img/ajax-loader-two.gif"/></p>');  
                                                $('#notificacionrec').load("notificacionrec.jsp");                                             
                                              }    
                                            
                                         var nombre = $(this).attr("name");                                        
					$('div[id^="c"]').fadeOut(0);     
                                        $('#c'+seleccionado).fadeIn(1000);                                        
					$('a[rel^="o"]').removeClass("selected");   
                                        					                                                                                                                                                                                                        
					if((seleccionado=="ocom")||(seleccionado=="ohis")||(seleccionado=="omue")||(seleccionado=="opue")||(seleccionado=="oide")||(seleccionado=="ofor"))
                                        {                            
                                            if(seleccionado == "oide")   
                                            {                                                            
                                                $('#conocimlabel').show(0);
                                                $('#depolabel').hide(0);   
                                            }    
                                            
                                            $('a[rel^="'+seleccionado+'"]').addClass("selected");
                                                
					}
					else{
						$('a[rel^="ocom"]').addClass("selected");					
						$('a[rel^="'+seleccionado+'"]').addClass("selected");
					}
					return false;				
				}							
			}
		});	
			

		var name					= "#sidebar";
		var sidebar_top_limit 		= 170;
		var sidebar_top_margin 		= 10;
		var sidebar_slide_duration	= 50;
		
		$(window).scroll(function() { 
			// Calculates the top offset adds the limit
			offset = $(document).scrollTop() + sidebar_top_margin;		
			// This keeps the sidebar away from the top of the page
			if(offset < sidebar_top_limit)
				offset = sidebar_top_limit;			
			// Animation
			$(name).animate({top:offset},{duration:sidebar_slide_duration,queue:false});
		});

		$('#hpage').click(function(){
			alert("Para que Grupo CICE sea su p\u00E1gina de Inicio, solo arrastre el icono de Grupo CICE de la pesta\xf1a de su navegador hacia el icono de p\u00E1gina de Inicio (comunmente una casa), y de click en SI.");		   
			return false;
		});

		$('#favor').click(function(){
			alert("Para que Grupo CICE este dentro de sus favoritos, puede presionar CTRL+D o, solo arrastre el icono de Grupo CICE de la pesta\xf1a de su navegador hacia el icono de p\u00E1gina de marcadores (comunmente una estrella), y de click en SI.");		   
			return false;
		});


	});

});

