/**
 * JS
 * @author Darío Ruellan <druellan@ecimtech.com>
 * @copyright ecimTech 2009
 */

$(function(){


// ** Header ***********************************

	// Seteamos el dropDown
	$("#header .dropdown").hover(function(){
		$(this).find("ul:first").slideDown();
	},
	function(){
		$(this).find("ul:first").stop('false','true').fadeOut();
	});

	// Seteamos submenues del dropDown
	$("#header .dropdown .submenu").hover(function(){
		$(this).find("ul").slideDown();
	},
	function(){
		$(this).find("ul").stop('false','true').fadeOut();
	});


// ** Aside ***********************************
	
	// Seteamos submenues
	$("#nav .dropdown").hover(function()
	{
		$("ul", this).show().css({
			width: 0,
			opacity: 0
		}).animate({
			opacity: 1,
			width: 210
		});

	}, function(){
		$("#nav .dropdown ul").stop(false,true).fadeOut();
	});
	
	$("#nav .dropdown li").hover(function()
	{
		$("a", this).addClass("rollover");
	}, function()
	{
		$("a", this).removeClass("rollover");
	});


// ** Textarea ***********************************


	var textarea = $("#textarea");
	
	// Activamos modales genéricos
	$.nyroModalSettings(
	{
		processHandler: function(settings)
		{
			settings.title = "";
			
			var url = settings.url;
			if (url && url.indexOf('http://www.youtube.com/watch?v=') == 0)
			{
				$.nyroModalSettings(
				{
					type: 'swf',
					height: 355,
					width: 425,
					url: url.replace(new RegExp("watch\\?v=", "i"), 'v/')
				});
			}
			else if (url)
			{
				$.nyroModalSettings(
				{
					minHeight: 960,
					width: 800
				});
			}
		}
	});
	
	$("a.modal", textarea).nyroModal({
		bgColor: '#000',
		contentError: 'Actualmente este contenido no está disponible.<br />Por favor, intente más tarde.<br /><a href="#" class="nyroModalClose">cerrar</a>',
		gallery: 'gal',
		closeButton: '<a href="#" class="nyroModalClose" id="closeBut"></a>',
		minWidth: 300,
  		minHeight: 270,
		galleryCounts: false
	});
	
	// Teansparencia de footer
	$("#footer").css("opacity", "0.7");
	
	// Iniciammos tooltips
	$(".tooltip").each(function()
	{
		var grav = "s";
		if ( $(this).hasClass("north") )
			grav = "n";
		if ( $(this).hasClass("east") )
			grav = "e";
		if ( $(this).hasClass("west") )
			grav = "w";
		if ( $(this).hasClass("south") )
			grav = "s";
		$(this).tipsy(
		{
			fade: true,
			gravity: grav
		});
	});

});
