/**
 * @author Fábio Miranda Costa <fabiomcosta@gmail.com>
 */
var count=1;
var imgObj = new Image();
imgObj.src = "http://inativas.maxmeio.com/portalfacex/fundamental/imgs/ajax-loader2.gif";
imgObj.alt= "";
imgObj.id = "load_img_prog_cinema";
var imgsNumber = arrayImg.length;
var tmOut;
var TIME = 6000;



jQuery.fn.mFadeOut = function(){
	$(this).animate({"opacity":1},"fast");
}

jQuery.fn.mFadeIn = function(objImg){
	$(this).animate({"opacity":0},"fast",function(){
				$("#container_img_box_imagem").get(0).removeChild($(this).get(0))
				$("#container_img_box_imagem").prepend(objImg);
				$("#legendas_cinema").html(arrayLegendas[count-1]);
				$("#foto_slide").mFadeOut();
			});
}

function onLoadFunc(obj){
	document.getElementById("container_img_box_imagem").removeChild(imgObj);
	$("#foto_slide").mFadeIn(obj);
	tmOut = setTimeout("timeOut()",TIME);
}


jQuery.fn.changeImg = function(sinal){
			if(sinal == "+"){
 				if(count == imgsNumber)
 					count = 1;
 				else
 					count++;
 			}
			else{
 				if(count == 1)
 					count = imgsNumber;
 				else
 					count--;
 			}
			
			clearTimeout(tmOut);

			document.getElementById("container_img_box_imagem").appendChild(imgObj);
			var lancImg = $("<img src='"+pasta+arrayImg[count-1]+"' id='foto_slide' ></img>");
			lancImg.css({"display":"none","opacity":0});
			lancImg.load(function(){onLoadFunc($(this))});
			lancImg.mouseover(function(){clearTimeout(tmOut)}).mouseout(function(){clearTimeout(tmOut);tmOut = setTimeout("timeOut()",TIME);});
}

	
	function timeOut(){
		$("#next_btn").changeImg("+");
	}
	
	$(window).load(function(){
		$("#next_btn").click(function(){ $(this).changeImg("+");return false; });
		$("#prev_btn").click(function(){ $(this).changeImg("-");return false; });
		tmOut = setTimeout("timeOut();",TIME);
		$("#foto_slide").mouseover(function(){
											clearTimeout(tmOut)
										  }).mouseout(function(){
											clearTimeout(tmOut);
											tmOut = setTimeout("timeOut()",TIME);
										  });
	});
	
	
	
