var host = "http://www.tome.cl";
//Portada

//Rotacion FlashNews

function newsTicker(currentItem) {  
		  
	    //work out new anim duration  
	    var distance = currentItem.width(),  
	    duration = (distance - Math.abs(parseInt(currentItem.css("marginLeft")))) / 0.025;  
	  
	    //animate the first child of the ticker  
	    currentItem.animate({ marginLeft: -distance }, duration, "linear", function() {  
	  
	      //move current item to the bottom     
	    	currentItem.appendTo(currentItem.parent()).css("marginLeft", 0);  
	  
	    //recurse  
	    //newsTicker(currentItem.parent().children(":first"));
	      newsTicker(currentItem);
	    });  
	  };
  
	  function mycarousel_initCallback(carousel)
	  {
	      // Disable autoscrolling if the user clicks the prev or next button.
	      carousel.buttonNext.bind('click', function() {
	          carousel.startAuto(0);
	      });

	      carousel.buttonPrev.bind('click', function() {
	          carousel.startAuto(0);
	      });

	      // Pause autoscrolling if the user moves with the cursor over the clip.
	      carousel.clip.hover(function() {
	          carousel.stopAuto();
	      }, function() {
	          carousel.startAuto();
	      });
	  }

	  function sliderPato(contenedor)
	  {
		  	var distancia = contenedor.width(),  
		    duracion = (distancia - Math.abs(parseInt(contenedor.css("marginLeft")))) / 0.04;  
		  
		      
		    contenedor.animate({ marginLeft: -distancia }, duracion, "linear", function() {  
		  
		           
		    	contenedor.appendTo(contenedor.parent()).css("marginLeft", 0);  
		  
		    //recurse  
		    sliderPato(contenedor.parent().children(":first"));
		    sliderPato(contenedor);
		    });
	  }

$(document).ready(function(){
	$("a[rel^='pp']").prettyPhoto();
	//twitter
	var twitUsuario = "alcaldetome";
	var tweets = 5;//tweets a mostrar
	$.getJSON("http://twitter.com/status/user_timeline/"+twitUsuario+".json?count=5&callback=?",function(json){
	    var urlregex = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gi;
	    var userregex = /(\@([-A-Z0-9+&\/%?=~_|!:,.;]*))/gi;
	    var hashtagregex = /(\#([-A-Z0-9+&\/%?=~_|!:,.;]*))/gi;
	    var count = 0;
	    var html = "";
	    for (i=0;i<json.length;i++)
	    {
	      if (json[i].in_reply_to_screen_name==null)
	      {
	       html += "<span class='redtext'>@alcaldetome:</span> <span class='' style='margin:0 5px;'>" + json[i].text.replace(urlregex,"<a class='url' href='$1' rel='nofollow'>$1</a>").replace(userregex,"<a class='user' href='http://twitter.com/$2' rel='nofollow'>$1</a>").replace(hashtagregex,"<a class='hashtag' href='http://twitter.com/#search?q=$1' rel='nofollow'>$1</a>") + "</span>";	        
	        count++;
	      }
	      if (count >= tweets) break;
	    }
	    
	    // incluimos el html dentro del div myTwitter
	    $("#noticias").append(html);
	  });
	$('#actividadesverano').cycle({
	fx: 'fade', // choose your transition type, ex: fade, scrollUp, shuffle, etc...
	timeout:    5200
	});

	//slider top
	sliderPato($("#slid"));
	
	//var t = temperaturas['Concepci&oacute;n'].split("|");
	//var p = pronosticos['Concepci&oacute;n'].split("|");
	//var d = fechas['Concepci&oacute;n'].split("|");
	//var i = iconos['Concepci&oacute;n'].split("|");
	//if(i[0]=="cubierto.gif" || i[0]=="niebla.gif"){
	//	var im = host+"/img/front/clima/parcial.png";
	//}
	//if(i[0]=="sol.gif"){
	//	var im = host+"/img/front/clima/soleado.png";
	//}
	//if(i[0]=="lluvia.gif" || i[0]=="llovizna.gif"){
	//	var im = host+"/img/front/clima/lluvia.png";
	//}
	//var ic = i[0].split(".");
	//var html = '<div class="boxC span-7">'+
	//			'<div class="span-3"><img src="http://www.meteochile.gob.cl/iconosmeteo/'+ic[0]+'.png" width="100"/></div>'+
	//			'<div class="" style="position:relative;top:5px;left:5px;"><strong style="display:block;font-size:1.5em;">'+d[0]+'</strong>'+p[0]+'</div>'+				
	//		   '</div>'+
	//		'<small class="clear right tar" style="position:relative;top:-12px;left:80px;">Fuente: www.meteochile.gob.cl</small>';
	//$("#climaWidget").html(html);	
	//$('ul li:has(ul)').hover( 
	//	      function(e) 
	//	      { 
	//	         $(this).find('ul').css({display: "block"});		         
	//	      }, 
	//	      function(e) 
	//	      { 
	//	         $(this).find('ul').css({display: "none"}); 
	//	      } 
	//	   ); 
	//$(".defecto").css({display: "block"});
	//$('ul.smenu li:has(div)').hover( 
	//	      function(e) 
	//	      { 
	//	         $(this).find('div').css({display: "block"});
	//	         $(".defecto").css({display: "none"});
	//	      }, 
	//	      function(e) 
	//	      { 
	//	         $(this).find('div').css({display: "none"});
	//	         $(".defecto").css({display: "block"});
	//	      } 
	//	   ); 
	
	$("#featured").tabs({fx:{opacity: "toggle"}}).tabs("rotate", 7000, true);
	newsTicker($(".newsContainer"));
	
	//Actividades Recientes
	var margin = -10;	
	$("#subirRecientes").click(function(){
		margin = margin - 70;
		if(margin < -430){
			margin = margin + 70;
		}
		$(".actRecientes").animate({
			marginTop:margin+"px",
			height:'slideUp'
		},1000, function(){
			//$("#t").html(margin);
		});
	});
	
	$("#bajarRecientes").click(function(){
		margin = margin + 70;
		if(margin > -10){
			margin = margin - 70;
		}
		$(".actRecientes").animate({
			marginTop:margin+"px",
			height:'slideDown'
		},1000, function(){
			//$("#t").html(margin);
		});
	
		// Accesos Directos
		
	});
	var distancia = 0;
	$("#avanzarAccesos").click(function(){
		distancia = distancia - 400;
		if(distancia < -800){
			distancia = distancia+ 400;
		}
		$(".accesosDirectos").animate({
			marginLeft:distancia+"px",
			width:'linear'
		},1000, function(){
			$("#t").html(distancia);
		});
	});
	
	$("#retrocederAccesos").click(function(){
		distancia = distancia+ 400;
		if(distancia > 0){
			distancia = distancia - 400;
		}
		$(".accesosDirectos").animate({
			marginLeft:distancia+"px",
			width:'linear'
		},1000, function(){
			$("#t").html(distancia);
		});	
	});
	
	$("a#imprimir")
			.attr("href", "javascript:void(0)")
			.click(
			function(){
				// Print the DIV.
				$(".printable").print();
				// Cancel click event.
				return(false);
				});
	
});

