
var pos=0;
var pos_frase=0;
var max=0;
var len=0;
var len_frase=0;
var inc=459;
var mov=false;
play=true;
jQuery(document).ready(function(){
len=jQuery("#tira .moduletable_exclusiva").length;
max=inc*(len-1)*-1;
pos=0;
jQuery("#tira").css("width",len*inc);
//console.log(pos);
setTimeout("autoplay()",5000);
var total=jQuery(".moduletable_exclusiva").length;
	jQuery(".moduletable_exclusiva").each(function(i){

		var html='<div class="pager">';
				if(i!=0){		html+='<a href="javascript://" onclick="left();"><img src="templates/cosmo2008/img/arrow2.gif" alt="" style="float:none;"/></a>'; }
								html+='<span><a href="#">'+(i+1)+'</a> de <a href="#">'+total+'</a></span>';
				if(i<(total-1)){	html+='<a href="javascript://" onclick="right();"><img src="templates/cosmo2008/img/arrow.gif" alt="" style="float:none;"/></a>'; }
				html+='</div>'
		jQuery(this).append(html);

	});
	len_frase=jQuery(".moduletable_frase").length;
	jQuery(jQuery(".moduletable_frase").hide().get(0)).show();
	jQuery("table#infinity_menu_1 tr").append("<td style='width:100%'> </td>");



});

//console.log(len,max);

function autoplay(){
	if(play){
		if(pos>max && !mov){	
			mov=true;
			pos-=inc;
			jQuery("#tira").animate({marginLeft: pos},500,function(){
				mov=false;
			});
		}
		else{
			mov=true;
			pos=0;
			jQuery("#tira").animate({marginLeft: pos},500,function(){
				mov=false;
			});
		}
	}
	setTimeout("autoplay()",5000);
}
function left(){
	if(pos<0  && !mov){	
		play=false;
		mov=true;
		pos+=inc;
		jQuery("#tira").animate({marginLeft: pos},500,function(){
			mov=false;			
			play=true;
		});
	}
}
function right(){
//console.log(pos);
	if(pos>max && !mov){	
		play=false;
		mov=true;
		pos-=inc;
		jQuery("#tira").animate({marginLeft: pos},500,function(){
			mov=false;
			play=true;
		});
	}
}


function next(){
		pos_frase=(pos_frase+1)%len_frase;
		
		jQuery(jQuery(".moduletable_frase").hide().get(pos_frase)).show();
}
function previous(){
	pos_frase=(pos_frase-1);
	if(pos_frase<0) pos_frase=len_frase+pos_frase;
	pos_frase%=len_frase;
		
		jQuery(jQuery(".moduletable_frase").hide().get(pos_frase)).show();
}





