$(function(){

	//Elementos
	var $navHome2 = $('#navHome2'),
		$navHome2Blt = $('#navHome2Blt'),
		$navHome2Lst = $('#navHome2Lst'),
		p = null;
		

	//ajuste do tamanho e posicao do nav
	var navHSize = $navHome2Blt.find('ul li').size();
//	alert(navHSize);
	$navHome2Blt.find('ul').width((20*navHSize)+20);
	

	//ajuste do tamanho e posicao do slider
	var boxWidth = $navHome2.width(),
		lstSize = $navHome2.find('ul li').size();
	$('#navHome2Lst li').width(boxWidth);
	$('#navHome2Lst li > a').width(boxWidth);
	$navHome2Lst.find('ul').width((boxWidth*lstSize));
	
	//clique
	var intervalo;
	$navHome2Blt.find('a').click(function(event){event.preventDefault();
		clearInterval(intervalo);
		$(this).parents('li').siblings('.atv').removeClass('atv').end().addClass('atv');
		var listItem = $(this).parents('li');
//		alert('pos='+boxWidth+' size= '+$navHome2Blt.find('li').index(listItem));
		scrolling(boxWidth,$navHome2Blt.find('li').index(listItem));
		autoSlider();
	});

	// automatico do slider
	function autoSlider(){
		intervalo = window.setInterval('clickTimer()', 20000);
		fullLink();
	}
	autoSlider();

	// função
	function scrolling(size,pos){
		var sm = "-" + pos * size; 
//		alert(sm);
		$navHome2Lst.find('ul').stop(true , false).animate({left: sm} , 1500, 'easeInOutCubic');	
		p = pos;

	}
		
	function fullLink() {		

		if(!p){p = 0};
		var //f = $('#navHome2Lst	ul li:eq('+p+') a').attr('rel'),
			l =	$('#navHome2Lst ul li:eq('+p+') a').attr('href'),
			t = $('#navHome2Lst ul li:eq('+p+') a').attr('title');
		
		//if (f == "fullscreen"){
			$('#navHomeMask').html('<a href="'+l+'" title="'+t+'" style="display:block; height:200px; text-indent:-99999px">'+t+'</a>')
		//}else{
			//$('#navHomeMask').html('&nbsp;')
		//}
			
	}	
		
				
		

	// VALIDACAO DE PRIMEIRO ACESSO.
	var COOKIE_NAME = 'home';
	var options = { path:'/', expires:10};
	/*if ($.cookie('home') == null){
		$.cookie('home', '1', options);
		$('.modalHome').show();
	}*/
	// MODAL HOME
	var $al = $('body').height();
	var $la = $('body').width();
	$('.overlay').css('width' , $la).css('height',$al);
	$('.pular').click(function(){
		$('.modalHome * , .modalHome').fadeOut(1000);	
	})	
});

// automatico do slider
function clickTimer(){
	var $atvItm = $('#navHome2Blt').find('ul li.atv');		
	if($atvItm.next('li').find('a').attr('href')){
		$atvItm.next('li').find('a').click();
	}else{
		$('#navHome2Blt').find('ul li:first').find('a').click();
	}
}

