$(document).ready(function(){
	$("#featured > ul").tabs({fx:{opacity: "toggle"}}).tabs("rotate", 5000, true);
	$(function() {
		$("#mensagensLista").jCarouselLite({
			vertical: true,
			hoverPause:true,
			visible: 1,
			auto:4500,
			speed:1000
		});
	});
	
	atualizaTocandoAgora();
	

	$("a[rel='lightbox']").colorbox({ 'current': 'imagem {current} de {total}', previous: 'ANT', next: 'PRO', 'close': 'Fechar'});
	
	$(function() {
		$('a[rel*=external]').click( function() {
			window.open(this.href);
			return false;
		});
	});
	
	
	$(".displayInlineFancybox").colorbox({ 'current': 'imagem {current} de {total}', previous: 'ANT', next: 'PRO', 'close': 'Fechar', inline:true});
});

function mycarousel_initCallback(carousel)
{
    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
       	carousel.startAuto();
    });

    jQuery('#mycarousel-next').bind('click', function() {
        carousel.next();
        return false;
    });

    jQuery('#mycarousel-prev').bind('click', function() {
        carousel.prev();
        return false;
    });
};


jQuery().ready(function(){
	jQuery('#bannersIndex').jcarousel({
        scroll: 1,
		auto: 8,
        animation: 500,
		wrap: 'both',
		initCallback: mycarousel_initCallback
    });
});




function atualizaTocandoAgora() {
	var tsTimeStamp3= new Date().getTime();
	$.get("http://www.capitalfm.com.br/wp-content/themes/default/proxima_musica.php", { action: "get", time: tsTimeStamp3}, function (data){tratarResultadoTocandoAgora(data);});
}

function tratarResultadoTocandoAgora(resultado) {
	$("#tocandoAgora").remove();
	$("#tocandoAgoraLive").html(resultado);
}

var repetidor3 = window.setInterval('atualizaTocandoAgora()', 60000);

function openWebRadio() {
	var deviceAgent = navigator.userAgent.toLowerCase();
	var agentID = deviceAgent.match(/(iphone|ipod|ipad)/);
	if (agentID) {
		//window.open('http://www.capitalfm.com.br/aovivo.m3u', 'playerCapitalFM');
		location.href = "http://www.capitalfm.com.br/aovivo.m3u";
	}
	else {
		window.open('http://www.capitalfm.com.br/ao-vivo/', 'playerCapitalFM', 'height=405, width=700, toolbar=no');
	}
	return false;
}





function enviarForm() {
	var nome = $("input#nome").val();
	var email = $("input#email").val();
	var pedido = $("textarea#pedido").val();
	
	var dadosEnviar = 'nome=' + nome + '&email=' + email + '&pedido=' + pedido;
	
	$.ajax({
		type: "GET",
		url: 'http://www.capitalfm.com.br/wp-content/themes/default/formEmail.php',
		data: dadosEnviar,
		success: sucessoGetCadastro,
		cache: false
	});

	return false;
}

function sucessoGetCadastro(retorno) {
	
	$("#resultadoPedido").removeClass();
	
	var msgRetorno = '';
	
	if(retorno == "CAMPOSVAZIOS") {
		msgRetorno = "Você esqueceu de preencher algum campo. Por favor verifique e tente novamente.";
		$("#resultadoPedido").addClass('warning');
	}
	
	if(retorno == "EMAILERRO") {
		msgRetorno = "Você digitou um email inválido. Por favor verifique e tente novamente.";
		$("#resultadoPedido").addClass('warning');
	}
		
	if(retorno == "CADASTROOK") {
		msgRetorno = "Obrigado, seu pedido de música foi enviado com sucesso!";
		clearForm();
		$("#resultadoPedido").addClass('sucess');
	}
	
	$("#resultadoPedido").html(msgRetorno);
	$("#resultadoPedido").slideDown('slow');
}


function clearForm() {
        $(':input').each(function() {
            var type = this.type;
            var tag = this.tagName.toLowerCase();

            if (type == 'text' ||
                type == 'hidden' ||
                tag == 'textarea') {
                this.value = "";
            }
            else if (type == 'checkbox' ||
                type == 'radio') {
                this.checked = false;
            }
            else if (tag == 'select') {
                if (this.size > 1) {
                    this.options.length = 0;
                }
                else {
                    this.selectedIndex = -1;
                }
            }
        });
}



function enviarFormInfo() {
	
	var nome = $("input#nomeInfo").val();
	var email = $("input#emailInfo").val();
	
	var dadosEnviar = 'nome=' + nome + '&email=' + email;
	
	$.ajax({
		type: "GET",
		url: 'http://www.capitalfm.com.br/wp-content/themes/default/formCadastra.php',
		data: dadosEnviar,
		success: sucessoGetCadastroInfo,
		cache: false
	});

	return false;
}

function sucessoGetCadastroInfo(retorno) {
	
	$("#resultadoCadastro").removeClass();
	
	var msgRetorno = '';
	
	if(retorno == "CAMPOSVAZIOS") {
		msgRetorno = "Você esqueceu de preencher algum campo. Por favor verifique e tente novamente.";
		$("#resultadoCadastro").addClass('warning');
	}
	
	if(retorno == "EMAILERRO") {
		msgRetorno = "Você digitou um email inválido. Por favor verifique e tente novamente.";
		$("#resultadoCadastro").addClass('warning');
	}
		
	if(retorno == "CADASTROOK") {
		msgRetorno = "Obrigado, seu email foi cadastrado com sucesso!";
		clearFormInfo();
		$("#resultadoCadastro").addClass('sucess');
	}
	
	$("#resultadoCadastro").html(msgRetorno);
	$("#resultadoCadastro").slideDown('slow');
}


function clearFormInfo() {
        $(':input').each(function() {
            var type = this.type;
            var tag = this.tagName.toLowerCase();

            if (type == 'text' ||
                type == 'hidden' ||
                tag == 'textarea') {
                this.value = "";
            }
            else if (type == 'checkbox' ||
                type == 'radio') {
                this.checked = false;
            }
            else if (tag == 'select') {
                if (this.size > 1) {
                    this.options.length = 0;
                }
                else {
                    this.selectedIndex = -1;
                }
            }
        });
}


function clickclear(thisfield, defaulttext) {
	if (thisfield.value == defaulttext) {
	thisfield.value = "";
	}
	return false;
}

function clickrecall(thisfield, defaulttext) {
	if (thisfield.value == "") {
	thisfield.value = defaulttext;
	}
	return false;
}

