// 
//  n e s t O r ( function.js @ gekkO[ v1 ] )
//  creado bajo el techo de __perceptive-studio__ el 2010-02-16
//  nestor arroba perceptive guion studio punto com
//  habiendo dicho eso, bienvenido a mi codigo
// 

function translator() { document.getElementById('searchsubmit').value = 'Buscar'; }


function extLink() {
	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";
		}
	}
}

// ======================================= JQUERY CODE =======================================
// ======================================= scroll toTOP =======================================
$(function() {
	$.fn.scrollToTop = function() {
		$(this).hide().removeAttr("href");
		if ($(window).scrollTop() != "0") {
			$(this).fadeIn("slow")
		}
		var scrollDiv = $(this);
		$(window).scroll(
			function() {
				if ($(window).scrollTop()=="0") {
					$(scrollDiv).fadeOut("slow")
				} else{
					$(scrollDiv).fadeIn("slow")
				}
			}
		);
		$(this).click(function() {
			$("html, body").animate({scrollTop:0},"slow")
		})
	}
	
	$("#toTop").scrollToTop();
});


// ======================================= Mas Recientes =======================================
$(function() {
	$("span#newComm").click(function() {
		$("ul.popComm").fadeOut(0);
		$("ul.newComm").fadeIn("slow");
	});
	
	$("span#popComm").click(function() {
		$("ul.newComm").fadeOut(0);
		$("ul.popComm").fadeIn("slow");
	});
});


// ======================================= TOOL TIP =======================================
(function($) {
	$.fn.myToolTip = function(options) {
		var defaults = {
			xOffset: 10,
			yOffset: 25,
			tooltipId: "myTooltip",
			clickRemove: false,
			content: "",
			useElement: ""
		};
		var options = $.extend(defaults, options);
		var content;

		this.each(function() {
			var title = $(this).attr("title");
			$(this).hover(function(e) {
				content = (options.content != "") ? options.content : title;
				content = (options.useElement != "") ? $("#" + options.useElement).html() : content;
				$(this).attr("title","");
				if (content != "" && content != undefined) {
					$("body").append("<div id='"+ options.tooltipId +"'>"+ content +"</div>");
					$("#" + options.tooltipId)
					.css("position","absolute")
					.css("top",(e.pageY - options.yOffset) + "px")
					.css("left",(e.pageX + options.xOffset) + "px")
					.css("display","none")
					.fadeIn("fast")
				}
			},
			function() {
				$("#" + options.tooltipId).remove();
				$(this).attr("title",title);
			});

			$(this).mousemove(function(e) {
				$("#" + options.tooltipId)
				.css("top",(e.pageY - options.yOffset) + "px")
				.css("left",(e.pageX + options.xOffset) + "px")
			});	

			if (options.clickRemove) {
				$(this).mousedown(function(e) {
					$("#" + options.tooltipId).remove();
					$(this).attr("title",title);
				});
			}
		});
	};
})(jQuery);


// ======================================= HEADER RANDOM AND STICKY POSTS =======================================
function my_slider_fx() {
	$('.newsBox div').hover(function(){
		$(this).stop().animate({
			opacity: 1,
			backgroundColor: "#black"
		});
	}, function(){
		$(this).stop().animate({
			opacity: 0.35,
			backgroundColor: "#fff"
		});
	});
	
	/*$('.newsBox div').hover(function(){
		$(this).find('img').animate({
			width: "100px"
		});
	}, function(){
		$(this).find('img').animate({
			width: "60px"
		});
	});*/
}



// ======================================= READY =======================================
$(document).ready(function() {
	translator();
	my_slider_fx();
	extLink();
	$('#sidebar a, #sidebar span').myToolTip();
});
