/*******

	***	Portfolio by Charles Cavalcante ***
	*** http://www.mediagroup.com.br    ***
	
*****/

function Portfolio()
{
	this.dados = new Array();
	this.atual = 0;
	this.total = 0;
	this.top_ini = 362;
	this.top_fim = 390;
}
Portfolio.prototype.thumbs = function()
{
	$("#thumbs-img a").each(function(index, domElement)
	{ 
		$(this).attr("rel", $(this).position().left + "px");
	}).each(function(index, domElement)
	{ 
		this.style.position = "absolute"; 
		this.style.left = $(this).attr("rel"); 
	});
}
Portfolio.prototype.vai = function()
{
	this.atual++;
	if(this.atual >= this.total) this.atual = 0;
	var p = this.dados[this.atual];
	this.trocaIMG(p[2], p[1], p[0]);
}
Portfolio.prototype.vem = function()
{
	this.atual--;
	if(this.atual < 0) this.atual = this.total - 1;
	var p = this.dados[this.atual];
	this.trocaIMG(p[2], p[1], p[0]);
}
Portfolio.prototype.trocaIMG = function(img_url, cliente, job)
{
	var caller = this;
	
	$("#legenda").animate({ top: (this.top_fim + "px") }, 200, function()
	{ 
		$("#foto").fadeOut("slow", function()
		{
			$('#div_portfolio div.container').addClass('loading');
			
			var img = new Image();
			
		    $(img)
				.load(function () 
				{
					$(this).hide();
					
					$('#div_portfolio div.container').removeClass('loading');
					$("#foto").attr("src", img_url);
					$("#legenda b").html(cliente);
					$("#legenda span").html(job);
					
					caller.anima();
					
				})
				.attr('src', img_url);	
		}); 
	});
}
Portfolio.prototype.anima = function(novo)
{
	var caller = this;
	$("#foto").fadeIn("slow", function(){ $("#legenda").animate({ top: (caller.top_ini + "px") }, 300); });
};
Portfolio.prototype.MoveThumbs = function(dir)
{
	var caller = this;
	var w = 136;
	var posLeft = $("#thumbs-img").position().left;

	posLeft = posLeft + (dir=="dir"? -w : w);

	if(dir=="esq")
	{
		$("#thumbs-img a:last").css("position", "absolute");
		$("#thumbs-img a:last").css("left", $("#thumbs-img a:first").position().left - w);
		$("#thumbs-img a:last").prependTo("#thumbs-img div:first");
	}	
		
	$("#thumbs-img").animate({ left: posLeft }, 300, function()
	{
		if(dir=="dir")
		{
			$("#thumbs-img a:first").css("position", "absolute");
			$("#thumbs-img a:first").css("left", $("#thumbs-img a:last").position().left + w);
			$("#thumbs-img a:first").appendTo("#thumbs-img div:first");
		}	
	});
};