
/* Cookie */
jQuery.cookie=function(B,I,L){if(typeof I!="undefined"){L=L||{};if(I===null){I="";L.expires=-1}var E="";if(L.expires&&(typeof L.expires=="number"||L.expires.toUTCString)){var F;if(typeof L.expires=="number"){F=new Date();F.setTime(F.getTime()+(L.expires*24*60*60*1000))}else{F=L.expires}E="; expires="+F.toUTCString()}var K=L.path?"; path="+(L.path):"";var G=L.domain?"; domain="+(L.domain):"";var A=L.secure?"; secure":"";document.cookie=[B,"=",encodeURIComponent(I),E,K,G,A].join("")}else{var D=null;if(document.cookie&&document.cookie!=""){var J=document.cookie.split(";");for(var H=0;H<J.length;H++){var C=jQuery.trim(J[H]);if(C.substring(0,B.length+1)==(B+"=")){D=decodeURIComponent(C.substring(B.length+1));break}}}return D}};


var votedID=0;

jQuery(function($){

	$('.input').click(function(){
		$(this).attr('value','');
	})
				
    //Menu
	$('#jsddm > li').bind('mouseover', jsddm_open);
	$('#jsddm > li').bind('mouseout',  jsddm_timer);
	
	jQuery('#dvtop10').accordion({
			autoheight: true
		});
	
	$("#tiDDD").mask("99");
	$("#tiTelefone").mask("9999-9999");
	$("#tiRg").mask("9.999.999-99");
	$("#tiCpf").mask("999.999.999-99");
	$("#tiCep").mask("99.999-999");
	$("#tiNascimento").mask("99/99/9999");

	$.easing.backout = function(x, t, b, c, d){
		var s=0;
		return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
	};
	
	//slideShow();
	
	//Fotos
	$('.exibeLightbox').lightBox();
	  
	$("#resultado_ver").click(function() {
		var en = $("#enquete_id").val();
        $.get("http://radiomundialfm.com.br/resultado_enquete.php", {
            id: en
        },
        function(data) {
            $("#poll-container").html(data);
        });
        return false;
	});
	

	if ($.cookie('enquete_id') == $("#enquete_id").val()) {	
		$("#poll-container").empty();
		var enquete_id = $.cookie('enquete_id');
        $.get("http://radiomundialfm.com.br/resultado_enquete.php", {
            id: enquete_id
        },
        function(data) {
            $("#poll-container").html(data);
        });
        return false;
	}
		

	$("#tiCep").change(function(){		
			var cep = $("#tiCep").attr("value");
			$.get("http://radiomundialfm.com.br/correios.php", {
				tiCep: cep
			},
			function(data) {
				$("#recebe").html(data);
			});

			return false;
	});
	$("#recebecpf").hide();
	$("#tiCpf").change(function(){
			$("#recebecpf").show();
			var cpf = $("#tiCpf").attr("value");
			$.post("http://radiomundialfm.com.br/validacpf.php", {
				tiCpf: cpf
			},
			function(data) {
				$("#recebecpf").html(data);
			});

			return false;
	});


	$("#frmCont").validate({
		rules: {
				tiNome: "required",
				tiNascimento: "required",
				tiCpf: "required",
				tiEmail: "required",
				tiTelefone: "required"
				},
				messages: {
				tiNome: " ",
				tiNascimento: " ",
				tiCpf: " ",
				tiEmail: " ",
				tiTelefone: " "	
				}
	});

});


function textCounter(campo, countcampo, maxlimit) {
	if (campo.value.length > maxlimit) 
		campo.value = campo.value.substring(0, maxlimit); 
	else
		countcampo.value = maxlimit - campo.value.length; 
}

function external(path) { // pass in the correct path to the function so we only need one <A> for infinite amount of calls from  flash                          
// if the lightbox does not exist we will make it                       
	if ($('a#lightbox').length == 0) {                             
		$("body").append("</A><A id='lightbox' style='visibility: hidden; position: absolute; left: -9999px;' href='http://www.thetruetribe.com/+path+'>calling js lightbox from flash</A>");                            
		$('a#lightbox').lightBox();                   
		// if it already exists but the path is different we will set the new path                      
	} else if ($('a#lightbox').attr("href") != path) {                             
		$('a#lightbox').attr("href", path);                   
	}      
	// now we will simulate the click here.                         
	$('a#lightbox').trigger("click");      
}


function fechar_popup(){
    $("#popup").hide();
};

function insertEmoticon(addSmilie) {
    var addSmilie; var revisedMessage;
    var currentMessage = document.frmRecado.mural_shout.value;
    revisedMessage = currentMessage+addSmilie;
    document.frmRecado.mural_shout.value=revisedMessage;
    document.frmRecado.mural_shout.focus();
}



function slideShow() {

	//Set the opacity of all images to 0
	$('#gallery a').css({opacity: 0.0});
	
	//Get the first image and display it (set it to full opacity)
	$('#gallery a:first').css({opacity: 1.0});
	
	//Set the caption background to semi-transparent
	$('#gallery .caption').css({opacity: 0.7});

	//Resize the width of the caption according to the image width
	$('#gallery .caption').css({width: $('#gallery a').find('img').css('width')});
	
	//Get the caption of the first image from REL attribute and display it
	$('#gallery .content').html($('#gallery a:first').find('img').attr('rel'))
	.animate({opacity: 0.7}, 400);
	
	//Call the gallery function to run the slideshow, 6000 = change to next image after 6 seconds
	setInterval('gallery()',6000);
	
}

function gallery() {

	//if no IMGs have the show class, grab the first image
	var current = ($('#gallery a.show')?  $('#gallery a.show') : $('#gallery a:first'));

	//Get next image, if it reached the end of the slideshow, rotate it back to the first image
	var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('#gallery a:first') :current.next()) : $('#gallery a:first'));	
	
	//Get next image caption
	var caption = next.find('img').attr('rel');	
	
	//Set the fade in effect for the next image, show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1000);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	
	//Set the opacity to 0 and height to 1px
	$('#gallery .caption').animate({opacity: 0.0}, { queue:false, duration:50 }).animate({height: '1px'}, { queue:true, duration:300 });	
	
	//Animate the caption, opacity to 0.7 and heigth to 100px, a slide up effect
	$('#gallery .caption').animate({opacity: 0.7},100 ).animate({height: '40px'},500 );
	
	//Display the content
	$('#gallery .content').html(caption);
	
	
}
