// 
//  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 =======================================
/*
# DECLARACION DE GALERIAS
- por cada galeria se debe declarar su correspondiente linea indicando su nombre entre el "()"
$('#NOMBRE DE LA GALERIA a').lightBox();
*/
$(function() {
	$('#linkcat-13 a').lightBox(); // id de un set de imagenes
	$('#linkcat-507 a').lightBox(); // id de un set de imagenes
	$('#linkcat-9 a').lightBox(); // id de un set de imagenes
	
	$('a#gO-gallery').lightBox(); // id para una sola imagen
	
	$('div.gOGallery a').lightBox(); // gallery wordpress
	$('div.flickr-photos a').lightBox(); // gallery flickr
});


// ======================================= 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();
});

function prueba() {
	$(".newsBox div").mouseover(function() {
		$(this).animate({
			'opacity' : '1',
			'filter' : 'alpha(opacity=100)'
		},
		100);
	});
	
	$(".newsBox div").mouseout(function() {
		$(this).animate({
			'opacity' : '.4',
			'filter' : 'alpha(opacity=40)'
		},
		10);
	});
}


// ======================================= Mas Recientes =======================================
$(function() {
	$("span#theMost1").click(function() {
		$("ul.posts").fadeOut(0);
		$("ul.hits").fadeIn("slow");
	});
	
	$("span#theMost2").click(function() {
		$("ul.hits").fadeOut(0);
		$("ul.posts").fadeIn("slow");
	});
	
	$("span#lastComm1").click(function() {
		$("ul.commForo").fadeOut(0);
		$("ul.commBlog").fadeIn("slow");
	});
	
	$("span#lastComm2").click(function() {
		$("ul.commBlog").fadeOut(0);
		$("ul.commForo").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 =======================================
jQuery.fn.randomChild = function(aux) {
	return this.each(function() {
		var c = $(this).children().length;
		// var r = Math.ceil(Math.random() * c);
		// $(this).children().hide().parent().children(':nth-child(' + r + ')').show();
		
		$(this).children(':nth-child(' + aux + ')').animate({
			opacity: 1,
			borderBottom: "1px dashed #999",
			borderTop: "1px dashed #999"
		}).animate({
			opacity: 1,
			borderBottom: "1px dashed #999",
			borderTop: "1px dashed #999"
		},3000).animate({
			opacity: 0.35,
			borderBottom: "1px dashed #fff",
			borderTop: "1px dashed #fff"
		});
		
		$(this).children(':nth-child(' + aux + ')').find('img').animate({
			width: '100px'
		}).animate({width: '100px'},3000).animate({
			width: '60px'
		});
	});
};

function my_slider() {
	var aux = 1;
	var childs = $('.newsBox').children().length;
	
	setInterval(function() {
		$('.newsBox').randomChild(aux);

		if (aux == childs) aux = 1; else aux = aux + 1;
	},
	3500);
}

function my_slider_fx() {
	$('.newsBox div').hover(function(){
		$(this).stop().animate({
			opacity: 1,
			borderBottom: "1px dashed #999",
			borderTop: "1px dashed #999"
		});
	}, function(){
		$(this).stop().animate({
			opacity: 0.35,
			borderBottom: "1px dashed #fff",
			borderTop: "1px dashed #fff"
		});
	});
	
	$('.newsBox div').hover(function(){
		$(this).find('img').stop().animate({
			width: "100px"
		});
	}, function(){
		$(this).find('img').stop().animate({
			width: "60px"
		});
	});
}



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