var pos = 0;

var prev = function(){
	$('#prev').unbind('mousedown');
	if(pos == 0) {
		pos = (getQt() - 2)*-180;
		$('#h_notice ul').css('left',pos+'px');
	}
	pos += 180;
	$("#h_notice ul").animate({
		left: pos+"px"
	}, 750 );
	setTimeout(function(){$("#prev").mousedown(prev)},800);
}

var next = function(){
	$('#next').unbind('mousedown');
	if( pos == (getQt() - 1) * -180 ){
		pos=-180;
		$('#h_notice ul').css('left',pos+'px');
	}
	pos -= 180;
	$("#h_notice ul").animate({
		left: pos+"px"
	}, 750 );
	setTimeout(function(){$("#next").mousedown(next)},800);
}

function getQt() {
	return $('#h_notice ul li').length;
}

function defineSteps() {
	$("#h_notice ul li").eq(0).clone().appendTo('#h_notice ul');
	$("#h_notice ul li").eq(getQt() - 2).clone().prependTo('#h_notice ul');
	pos -= 180;
	$('#h_notice  ul').css('left', pos+'px');
	$("#prev").mousedown(prev);
	$("#next").mousedown(next);
}

function getFirstParameter(){
	var url = window.location + '';
	var xsplited = url.split('?');
	if(xsplited[1]){
		var zparams = xsplited[1].split('&');
		var zfirst = zparams[0].split('=');
		if(zfirst[0] != ''){
			return jQuery.trim(zfirst[0]);
		}
	}
	return false;
}

function showPreviewMessage(message){
	var style = 'position:absolute;top:20px;right:20px;padding:10px;font-weight:bold;font-size:2em;color:#EA305B;border:solid 1px #CD234B;background-color:#460010;';
	$("body").prepend('<div style="'+style+'" id="preview_message">Modo preview - '+message+'</div>');
}

function loadFaq() {
	var hotUrl 		= "#";
	var previewUrl 	= "#";
	if ( getFirstParameter() == 'previewFaq' ) {
		var url = previewUrl;
		//showPreviewMessage('FAQ');
	} else {
		var url = hotUrl;
	}
	$.getScript(url, function() {
		try {
			if (faq && faq.length > 0) {
					var str = '<ul>';
					for (i in faq) {
						if (parseInt(faq[i].home) == 1) {
							str += ('<li><a href="' + faq[i].irpara + '" title="' + faq[i].pergunta + '"> ' + faq[i].pergunta + ' </a></li>');
						}
					}
					str += '</ul>';
					$("#h_notice").html(str);
			}
		} catch (e) { }
		defineSteps();
	});
}

$(document).ready(function(){
	loadFaq();  //   FAQ POR JSON
	$('#eml').focus();
});