$(document).ready(function() {
	if($.browser.msie && ($.browser.version < 7)){ $("body").addClass("ie"); } //Adiciona uma classe para o IE6.
	$("#flashCerveja").flash({ src: '/swf/aCerveja.swf', width: 999, height: 496, wmode: 'transparent' }, { version: 8 });
	$("#flashGifts").flash({ src: '/swf/gifts.swf', width: 507, height: 497, wmode: 'transparent' }, { version: 8 });
	$("#flashContato").flash({ src: '/swf/contato.swf', width: 440, height: 496, wmode: 'transparent' }, { version: 8 });
	$("#flashCadastro").flash({ src: '/swf/cadastro.swf', width: 455, height: 402, wmode: 'transparent' }, { version: 8 });
	$("#flashHistoria").flash({ src: '/swf/historia.swf', width: 999, height: 496, wmode: 'transparent' }, { version: 8 });
	
	$(".playerRodada4").flash({ src: '/swf/playerPod.swf', width: 450, height: 200, wmode: 'transparent', flashvars: { mp3Path: ['/swf/mp3/novosmestres04.mp3'].join(' ')}}, { version: 8 });
	$(".playerRodada3").flash({ src: '/swf/playerPod.swf', width: 450, height: 200, wmode: 'transparent', flashvars: { mp3Path: ['/swf/mp3/novosmestres03.mp3'].join(' ')}}, { version: 8 });
	$(".playerRodada2").flash({ src: '/swf/playerPod.swf', width: 450, height: 200, wmode: 'transparent', flashvars: { mp3Path: ['/swf/mp3/novosmestres02.mp3'].join(' ')}}, { version: 8 });
	$(".playerRodada1").flash({ src: '/swf/playerPod.swf', width: 450, height: 200, wmode: 'transparent', flashvars: { mp3Path: ['/swf/mp3/novosmestres01.mp3'].join(' ')}}, { version: 8 });
	$("#flashHome").flash({ src: '/swf/home.swf', width: 999, height: 496, wmode: 'transparent', flashvars: {
		cervejaURL: ['/aCerveja.php'].join(' '), 
		giftsURL: ['/gifts.php'].join(' '),
		campanhasURL: ['/campanha.php'].join(' ')
	}}, { version: 8 });

	$("ul.listVideos li a.hover").each(function(){
		$flvURL = '/swf/flv/' + $(this).attr("rel").split("|")[1] + '.flv';
		$imgURL = $(this).attr("rel").split("|")[0];
		swfobject.embedSWF("/swf/playerCampanha.swf", "targetVideosMidia", "500", "500", "8", "", {},{wmode: 'transparent'}, {} );
		$localizaFlash = function(flvURL, imgURL){
			$flash = ($.browser.msie) ? window['targetVideosMidia'] : document['targetVideosMidia'];
			$flash.playVideo(flvURL, imgURL);
		}
		$time = setTimeout($localizaFlash,1000,$flvURL,$imgURL);
	});

	$("ul.listVideos li a").click(function(){
		$flvURL = '/swf/flv/' + $(this).attr("rel").split("|")[1] + '.flv';
		$imgURL = $(this).attr("rel").split("|")[0];
		$(this).parent().parent().find("a").removeClass("hover");
		$(this).addClass("hover");
		$flash = ($.browser.msie) ? window['targetVideosMidia'] : document['targetVideosMidia'];
		$flash.playVideo($flvURL, $imgURL);
		return false;
	});

	$("ul.listSpots li a").click(function(){
		$mp3URL = $(this).attr("href");
		$(this).parent().parent().find("a").removeClass("hover");
		$(this).addClass("hover");
		$flash = ($.browser.msie) ? window['targetVideosMidia'] : document['targetVideosMidia'];
		$flash.playAudio($mp3URL);
		return false;
	});

		/*
	$("ul.listMidia li a").click(function(){
		$imgURL = $(this).attr("href");
		$(this).parent().parent().find("a").removeClass("hover");
		$(this).addClass("hover");
		$flash = ($.browser.msie) ? window['targetVideosMidia'] : document['targetVideosMidia'];
		$flash.showPrint($imgURL);
		return false;
		tb_show('', '/img/thumb-impressos-03g.jpg?keepThis=true&width=753&height=496&modal=true', false);
		return false;
	});
		*/


	$("ul.listMidia li a").click(function(){
		$src = $(this).attr("href");
		$("#content").hide();
		$("#showImpresso #impressos img").attr("src", $src);
		$("#showImpresso").fadeIn();
		return false;
	});
	$("a#hideImpresso, #impressos").click(function(){
		$("#showImpresso").hide();
		$("#content").show();
	});
	 
	
	$("ul.videos a").click(function(){
		var flvURL = $(this).attr("rel");
		$("#videoCampanha").flash({ src: 'swf/playerVideo.swf', width: 455, height: 360, wmode: 'transparent', flashvars: { xml: [flvURL].join(' ') }}, { version: 8 });
		$("ul.videos a").removeClass("hover");
		$(this).addClass("hover")
		return false;
	});
	
	$(".previewWall").hoverIntent(function(){
		$(this).find(".content").fadeIn();
	}, function(){
		$(this).find(".content").fadeOut();
	});

	$(".previewWall ul.btns li a, ul.emoticon li a").click(function(){
		$url = $(this).attr("href");
		pageTracker._trackPageview($url);
		$initDownload = function(URL){
			window.location = URL;
		}
		setTimeout($initDownload,2000,$url);
		return false;
	});

    $("input + label").click(function() {
		if ($(this).prev().attr("type") == 'checkbox') {
			if ($(this).prev().is(":checked")) {
				$(this).prev().attr("checked", false);
			} else {
				$(this).prev().attr("checked", true);
			}
		} else {
			$(this).prev().attr("checked", true);
		}
    });

	
	$("#carrosselGaleria ul a").click(function(){
		$ano = $(this).attr("href").split("#")[1].split("-")[0];
		$mes = $(this).attr("href").split("#")[1].split("-")[1];
		$(this).parent().parent().find("a").removeClass("hover");
		$(this).addClass("hover");
		$.ajax({
			dataType: "html",
			url: '/inc/resultadosGaleria.html?ano=' + $ano + '&mes=' + $mes,
			success: function(html) {
				$("ol.destGaleria").html(html);
			}
		});
		return false;
	});

	$("#carrosselBandas ul a").click(function(){
		$ano = $(this).attr("href").split("#")[1].split("-")[0];
		$mes = $(this).attr("href").split("#")[1].split("-")[1];
		$(this).parent().parent().find("a").removeClass("hover");
		$(this).addClass("hover");
		$.ajax({
			//data: $("#formTwitter").serialize(),
			dataType: "html",
			url: '/inc/resultadosBandas.html?ano=' + $ano + '&mes=' + $mes,
			success: function(html) {
				$("ul.destBandas").html(html);
			}
		});
		return false;
	});

	$("#carrosselGaleria ul").jcarousel({ scroll: 2 });

	$("a.btnBandas").click(function(){
		$carousel = setTimeout('$("#carrosselBandas ul").jcarousel({ scroll: 2 })',100);
		$scroll = setTimeout('$("#scrollBanda").jScrollPane({ scrollbarWidth: 7, scrollbarMargin: 7, showArrows: false })',100);
		return false;
	});

	$("ul.destBandas li .txt").hover(function(){
		$(this).find(".player").fadeIn();
	}, function(){
		$(this).find(".player").fadeOut();
	});

	$("a.btnEnvieMusica").click(function() {
		tb_show('', '/tb/envieMusica.php?keepThis=true&TB_iframe=true&width=370&height=515&modal=true', false);
		return false;
	});

	$("a.btnPoliticaPrivacidade").click(function() {
		tb_show('', '/tb/politicaPrivacidade.html?keepThis=true&TB_iframe=true&width=467&height=486&modal=true', false);
		return false;
	});

	$("#scrollTermos").each(function(){
		$scroll = setTimeout('$("#scrollTermos").jScrollPane({ scrollbarWidth: 7, scrollbarMargin: 7, showArrows: false })',1000);
	});

	$("#scrollPolitica").each(function(){
		$scroll = setTimeout('$("#scrollPolitica").jScrollPane({ scrollbarWidth: 7, scrollbarMargin: 7, showArrows: false })',1000);
	});

	$("input[type=file]").filestyle({ 
		image: "../img/choose-file.gif",
		imageheight :  20,
		imagewidth : 60,
		width : 165
	});
	
    $("#formContato").validate({ errorContainer: $(".boxMsgError"), errorLabelContainer: $(".msgError"),
        submitHandler: function() {
            $.ajax({
                type: 'POST',
				data: $("#formContato").serialize(),
                dataType: "json",
                url: '/inc/processaContato.php',
                success: function(json) {
                    if (json.msg == "true") {
						$(".boxMsgSuccess").fadeIn();
						$(".contato").fadeOut();
						$("#formContato input, #formContato select, #formContato textarea").val("");
						$("a.btnVoltar").click(function() {
							$(".contato").fadeIn();
							$(".boxMsgSuccess").fadeOut();
							return false;
						});
					}else{
						$(".boxMsgIndisponivel").fadeIn();
						$(".contato").fadeOut();
						$("a.btnVoltar").click(function() {
							$(".contato").fadeIn();
							$(".boxMsgIndisponivel").fadeOut();
							return false;
						});

					}
                }
            });
        }
    });

    $("#formCadastro").validate({ errorContainer: $(".boxMsgErrorCad"), errorLabelContainer: $(".msgError"),
        submitHandler: function() {
            $.ajax({
                type: 'POST',
				data: $("#formCadastro").serialize(),
                dataType: "json",
                url: '/inc/processaCadastro.php',
                success: function(json) {
                    if (json.msg == "true") {
						$(".boxMsgSuccessCad").fadeIn();
						$(".contato").fadeOut();
						$("#formCadastro input, #formCadastro select, #formCadastro textarea").val("");
						$("a.btnVoltar").click(function() {
							$(".contato").fadeIn();
							$(".boxMsgSuccessCad").fadeOut();
							return false;
						});
					}else{
						$(".boxMsgErrorCad").fadeIn();
						$(".contato").fadeOut();
						$("a.btnVoltar").click(function() {
							$(".contato").fadeIn();
							$(".boxMsgIndisponivel").fadeOut();
							return false;
						});
					}
                }
            });
        }
    });

	
	$(".boxMsgSuccessBanco").each(function(){
		parent.pageTracker._trackPageview('/envie-sua-musica/sucesso/');
	});
	
	$("a.btnFechar").click(function() {
		parent.tb_remove();
		return false;
	});

	$("a.btnFecharMusica").click(function() {
		parent.tb_remove();
		return false;
	});
	
	$("a.btnFecharTb").click(function() {
		parent.tb_remove();
		return false;
	});

	$("input.cpf").blur(function(){
		var cpf = $(this).val();
		exp = /\.|\-/g
		cpf = cpf.toString().replace( exp, "" );
		if (cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999"){
			$(this).val("");
			alert('CPF Invalido!');
			return false;
		}
		add = 0;
		for (i=0; i < 9; i ++){
			add += parseInt(cpf.charAt(i)) * (10 - i);
		}
		rev = 11 - (add % 11);
		
		if (rev == 10 || rev == 11)
			rev = 0;
			
		if (rev != parseInt(cpf.charAt(9))){
			$(this).val("");
			alert('CPF Invalido!');
			return false;
		}	
		add = 0;
		for (i = 0; i < 10; i ++)
			add += parseInt(cpf.charAt(i)) * (11 - i);
			
		rev = 11 - (add % 11);
		if (rev == 10 || rev == 11)
			rev = 0;
		
		if (rev != parseInt(cpf.charAt(10))){
			$(this).val("");
			alert('CPF Invalido!');
			return false;
		}
		return true;
	});

	$("#formEnvieMusica").validate({ errorContainer: $(".boxMsgErrorMusica"), errorLabelContainer: $(".msgError") });
	$("#formPreHome").validate({ errorContainer: $(".msgError"), errorLabelContainer: $(".msgError") });
	$(".boxDestMestres").append('<img src="img/bg-boxDestMestres.png" width="377" height="343" alt="" class="png" style="position: absolute; top: 0px; left: 0px; z-index: 0;" />');
	$(".boxGaleria").append('<img src="img/bg-boxGaleria.png" width="393" height="454" alt="" class="png" style="position: absolute; z-index: 0;" />');
	$(".boxPreHome").append('<img src="img/bg-boxPreHome.png" width="353" height="517" alt="" class="png" style="position: absolute; z-index: 0;" />');
	$("#scrollGaleria").jScrollPane({ scrollbarWidth: 7, scrollbarMargin: 7, showArrows: false });
	$("ul.bandas, ol.destGaleria").idTabs();
	$("input.hint").hint();
    $("#estado").selectbox();
	$("input.cel").mask("99-9999-9999");
	$("input.nasc").mask("99/99/9999");
	$("input.cpf").mask("999.999.999-99");
	$("input.cep").mask("99999-999");
	$(".rating input").rating('enable');
	$(".fix, span.embNobelHome, .playerHome, .ilustraPreHome").ifixpng();
	
});

/* HINT */
/**
* @author Remy Sharp
* @url http://remysharp.com/2007/01/25/jquery-tutorial-text-box-hints/
*/
(function ($) {

$.fn.hint = function (blurClass) {
  if (!blurClass) { 
    blurClass = 'blur';
  }
    
  return this.each(function () {
    // get jQuery version of 'this'
    var $input = $(this),
    
    // capture the rest of the variable to allow for reuse
      title = $input.attr('title'),
      $form = $(this.form),
      $win = $(window);

    function remove() {
      if ($input.val() === title && $input.hasClass(blurClass)) {
        $input.val('').removeClass(blurClass);
      }
    }

    // only apply logic if the element has the attribute
    if (title) { 
      // on blur, set value to title attr if text is blank
      $input.blur(function () {
        if (this.value === '') {
          $input.val(title).addClass(blurClass);
        }
      }).focus(remove).blur(); // now change all inputs to title
      
      // clear the pre-defined text when form is submitted
      $form.submit(remove);
      $win.unload(remove); // handles Firefox's autocomplete
    }
  });
};

})(jQuery);
/* HINT */