$().ready( function() {

	webmail();

	newsHighlights();

	lastnews();

	var a = 1;
	var total = 5;
	var stage = 0;

	if(a < total){
		$.timer(8000, function (timer) {
			
			if(a < total && stage == 0) {
				a++;
				stage = 0;
			}
			else if(a > 1) {
				a--;
				stage = 1;
			}
			else if(a == 1) {
				a++;
				stage = 0;
			}

			if(stage == 0) $('.pagination a.next').click();
			else if(stage == 1) $('.pagination a.prev').click();

			//timer.stop();
		});		
	}

});

/////////////////////////////////* Lastnews */////////////////////////////////

function lastnews(){

	$('.pagination a').live("click", function(){

		var page = $(this).attr('href');
		//page = page.split('pagina=');
		//page = page[1];
		
		jQuery.ajax({
			type: "POST",
			url: "modules/home/ajax-news.php",
			data: "pagima="+page,
			success: newsResponse
		});

		return false;
	
	});

}

function newsResponse(response){

	$('.lastnews ul').fadeOut("slow", function(){

		$('.lastnews').html(response).find('ul').each(function(){
		
			$(this).hide().fadeIn("slow");
		
		});
	
	});

}

/////////////////////////////////* Webmail */////////////////////////////////

function webmail(){
	$('input[name=imapuser]').focus(function() {
		if( 'Usuário' == $(this).val() ) $(this).val('');
	});
	$('input[name=imapuser]').blur(function () {
         if( '' == $(this).val() ) $(this).val('Usuário');
    });
	
	$('input[name=pass]').focus(function() {
		if( 'Senha' == $(this).val() ) {
			$(this).replaceWith('<input class="pass" id="senha" name="pass" type="password" value="" />');
			$('input[name=pass]').focus();
		}
	});
}

/////////////////////////////* Highlights News */////////////////////////////

function newsHighlights() {
	$("#news-highlight").wslide({
		width: 700,
		height: 180,
		pos: 1,
		horiz: true
	});
}
