/*Necesario para validacion XHTML 1.0 Strict. No permite target="_blank" */
function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") && 
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}
window.onload = externalLinks;


$(document).ready(function(){

	//Tabs
	$(".feat ul, ").tabs(".feat_content > div", {effect: 'fade', fadeOutSpeed: 'fast', history: true});
	$(".tab_menu ul").tabs(".tab_menu_content > div", {effect: 'slide'});

	//News Ticker
	$("#newsticker").newsTicker();

	//Scroll to top
	$(window).scroll(function() {
		if($(this).scrollTop() != 0) {
			$('#toTop').fadeIn();	
		} else {
			$('#toTop').fadeOut();
		}
	});
	$('#toTop').click(function() {
		$('body,html').animate({scrollTop:0},400);
	});	
    
	//Scroll to #anchor     
	$(function(){
	  var target = location.hash && $('a[hash='+location.hash+']')[0];
	  if( target )
		  $.scrollTo( target, { speed:400 });
	}); 

	
	//Fade images on hover
	$("img").hover(function(){
		$(this).fadeTo(400, 0.6);
	},function(){
		$(this).fadeTo(400, 1.2);
	});


	//Switch classes
	$("a.switch").toggle(function(){
	  $(this).addClass("swap"); 
	  $("ul.switch").fadeOut("fast", function() {
	  	$(this).fadeIn("fast").removeClass("half"); 
		 });
	  }, function () {
      $(this).removeClass("swap");
	  $("ul.switch").fadeOut("fast", function() {
	  	$(this).fadeIn("fast").addClass("half");
		});
	});	
	
	//Superfish menu
	$("ul.sf-menu").supersubs({
				minWidth:    12,
				maxWidth:    27,
				extraWidth:  1
			}).superfish({
				delay: 200,
				speed: 'fast'
			});

	//Tooltip
	 $('.tooltip').tipsy({gravity: $.fn.tipsy.autoNS});

	//Lazy Load
	$(".cat_list img, .commentlist img").lazyload({ 
		placeholder: "images/grey.gif", effect: "fadeIn" 
	});

});
