/**
 * JS
 * @author Darío Ruellan <druellan@ecimtech.com>
 * @copyright ecimTech 2008
 */

$(function()
{
	
	// Slider -------------------------
	
	// Preload 
	
	var count = 0;

	$("#slide-images img").each(function(img)
	{
		if ( $(this).context.complete )
		{
			count++;
			if ( count > 3 )
			{
				$("#slide-loading").fadeOut();
			}
		}
		else
		{
			$(this).load(function()
			{
				count++;
				if ( count > 3 )
				{
					$("#slide-loading").fadeOut();
				}
			});

		}
	});

	$("#slide-services a").hover(
		function()
		{
			var product		= $(this).attr("rel");
			var serviceText = $(this).html();

			// Populate selector
			var container = $("#slide-selector div."+product+" a.text-services");
			if (!$(container).html()) 
			{
				$(container).html(serviceText.replace(".gif", "@.gif"));
			}
			
			// Bring all back to normal
			$("#slide-selector > div").stop(true, true).fadeOut("fast");
			
			// Show Selector
			var selector = $("#slide-selector div."+product);
			$(".text-services", selector).hide();
			$(".moreinfo", selector).hide();
			$(selector).css("height", "90px").show().css("opacity", 0).animate(
			{
				duration: 'fast',
				opacity: 1,
				height: '407px'
			});
			$(".text-services", selector).fadeIn("slow",
			function()
			{
				$(".moreinfo", selector).fadeIn("slow");	
			});
			
			// background
			if ( !$("#slide-images img.selected").hasClass("product") ) 
			{
				$("#slide-images img").css("z-index", "1");
				$("#slide-images img.selected").css("z-index", "2");
				$("#slide-images img").removeClass("selected");
				$("#slide-images img.img_" + product).hide().addClass("selected").css("z-index", "3").fadeIn();
			}
			
		});
	
	// Volvemos atrás los cambios
	
	$("#slide").hover( function(){},
	function()
	{
		slideRevert()
	});
/*	
	$("#slide-consulting").hover(
	function()
	{
		slideRevert()
	});
*/	
});

/*
* Revertimos el slide
*/
function slideRevert()
{
	$("#slide-selector > div").stop(true, true).fadeOut("fast");
}