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


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
	$('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);
	});
}


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


// ======================================= GALLERY =======================================
function header() {
	$('#sets_3').cycle({
		fx: 'fade', speed: 1500, timeout: 1, pager: '#sets_control'
	});
	
	// alert($('#sets_control').children().length)
	i = 1;
	$('#sets_control').children().each(function() {
		$(this).html('<img src="/wp-content/themes/ada/images/header/small/sets_small-' + i + '.jpg" alt="Sets Small - Image ' + i + '" />');
		i = i + 1;
	});
	
}



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