/**
 * JS
 * @author Darío Ruellan <druellan@ecimtech.com>
 * @copyright ecimTech 2009
 */

$(function(){


// ** Header ***********************************

	// Seteamos el dropDown
	$("#header .dropdown").hover(function(){
		$(this).find("ul").slideDown("fast");
	},
	function(){
		$(this).find("ul").stop('false','true').fadeOut("fast");
	});


// ** Aside ***********************************
	

	// Seteamos submenues
	$("#nav .dropdown ul").css("width", "0");
	$("#nav .dropdown").hover(function()
	{
		$("ul", this).show().animate(
		{
			width: 240
		},"fast");

	}, function(){
		$("#nav .dropdown ul").stop(false,true).fadeOut("fast", function(){ $(this).css("width", "0") });
	});


// ** 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/')
				});
			}
		}
	});
	$("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
	});
	
	// 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
		});
	});

});