$.fontSizeChange = function(element){
	
	var IE6 = (navigator.userAgent.indexOf("MSIE 6")>=0) ? true : false;
	
	if ($.cookie('fontSize')){
		var originalFontSize = $.cookie('fontSize');
	}else{
		var originalFontSize = $(element).css('font-size');
		$.cookie('fontSize','16'); // set cookie
	}
	
	if(IE6) {
  		$(element).css('font-size', '16' );
	}else{
		$(element).css('font-size', $.cookie('fontSize')+'px');
	}
	
	
	// Increase Font Size
	
	$(".increaseFont").click(function(){
		if(IE6) {
			var currentFontSize = $(element).css('font-size');
			var currentFontSizeNum = parseFloat(currentFontSize, 10);	
			var newFontSize = currentFontSizeNum*1.1;
			if (newFontSize < 22) {
				$(element).css('font-size', newFontSize);
			};	
		}else{
			var currentFontSize = $.cookie('fontSize');
			var newFontSize = parseFloat(currentFontSize) + 1;
			if (newFontSize < 22) {
				$.cookie('fontSize', newFontSize, 365); // set cookie
				$(element).css('font-size', newFontSize);
			};	
		}
		return false;
	});
	
	// Decrease Font Size
	
	$(".decreaseFont").click(function(){
		if(IE6) {
			$(element).css('font-size', '16px');
		}else{
			var currentFontSize = $.cookie('fontSize');
			var newFontSize = parseFloat(currentFontSize) - 1;
			if (newFontSize > 15) {
				$.cookie('fontSize', newFontSize, 365); // set cookie
				$(element).css('font-size', newFontSize);
			};
		}
		return false;
	});
	
	
	//alert($.cookie)
	
};

// Funcao que seta o tamanho da fonte de acordo com o cookie
$.fontSizeSet = function(element){
	$(element).css('font-size', $.cookie('fontSize'));
};

//Funcao para troca de folha de estilos

$(document).ready(function() {
/*---------------------------------------------------*/
	// Funcao para limpar o conteudo do input da pagina de blog
/*---------------------------------------------------*/
	swapValue = [];
	$("input.input-value").each(function(i){
	   swapValue[i] = $(this).val();
	   $(this).focus(function(){
		  if ($(this).val() == swapValue[i]) {
			 $(this).val("");
		  }
	   }).blur(function(){
		  if ($.trim($(this).val()) == "") {
			 $(this).val(swapValue[i]);
		  }
	   });
	});
/*
	$('.styleswitch').click(function(){
	setActiveStyleSheet(this.getAttribute("rel"));
	window.location.reload();
	return false;
	});
	*/
	var c = $.cookie('style');
	var vCor='';
	if (c) {
		$('.styleswitch').removeClass('on');
		if(c=='contraste'){
			vCor='1';
			$('.styleB').addClass('on');
		}else{
			vCor='0';
			$('.styleA').addClass('on');
		}
	}
   if ( $("#flashHome").length > 0 ) {
	$('#flashHome').flash(
		{ src: '/swf/home.swf',
		width: '100%',
		height: 300,
		flashvars:{vCor:vCor},
		wmode: 'transparent' },
		{ version: 8 }
	);
   }
   
   if ( $(".videoFLV").length > 0 ) {
		$('.videoFLV').flash(
			{ src: '/public/repositorio_festa/videos/player_videoURL.swf',
			width: '465',
			height: '397',
			flashvars:{videoURL:'/public/repositorio_festa/videos/'+$('.videoFLV').attr("id")+'.flv'},
			wmode: 'transparent' },
			{ version: 8 }
		);
   }

// masks
	$("#cdata, #cdata2").mask("99/99/9999");
	$("#ccpf").mask("999.999.999-99");
	$("#ccep, #ccep2").mask("99999-999");
	$("#ctelefone, #ctelefone2, #cfax").mask("99999999");
	
	$("#ccnpj").mask("99.999.999/9999-99");
	
	$.fontSizeSet('body');
	$.fontSizeChange('body');
	
// regulamento forms
	$('#linkRegulamento').click(function(){
		$('#cregulamentotext').toggle();
		$('div.regulamentoStyles').toggleClass('cinquentaPx');
		$('div.regulamentoStyles').toggleClass('centoCinquentaPx');
	});
// aqui vc encontra
	$('#encontraLink').click(function(){
		$('#encontraContent').slideToggle("slow");
		$(this).toggleClass('mais');

		if($('.sidebar').css('margin-top')=='30px'){
			$('.sidebar').animate({
				marginTop:'230px'
			}, 600);
			
		}else{
			$('.sidebar').animate({
				marginTop:'30px'
			}, 600);
		}
	});
	
// hints forms
	hintFunc = function(){
		$("input, select, textarea").click(function() {
			$(this).next("span").addClass("hitOn");
		});
		$("input, select, textarea").focus(function() {
			$(this).next("span").addClass("hitOn");
		});
		$("input[checkbox], input[radio]").click(function() {
			$(this).next("span").addClass("hitOn");
		});
		$("input, select, textarea").change(function () {
			$(this).next("span").removeClass("hitOn");
		});
		$("input, select, textarea").blur(function () {
			$(this).next("span").removeClass("hitOn");
		});
	}
	hintFunc();
	
// index galeria	
	$(".work a").hover(
		function () {
			$(this).next("div.rating").css("display", "block");
		}, 
		function () {
			$(this).next("div.rating").css("display", "none");
		}
	);	
	$("div.rating").hover(
		function () {
			$(this).css("display", "block");
		}, 
		function () {
			$(this).css("display", "none");
		}
	);
});

// troca logos

	trocaLogos = function(check){
		if(check == 0){
			$('.btReal').hide();
			$('.btSantander').hide();
			$('.btGrupoSantander').fadeIn("slow");
			timer=setTimeout("trocaLogos(1)", 5000)
		}else if(check == 1){
			$('.btGrupoSantander').hide();
			$('.btReal').fadeIn("slow");
			$('.btSantander').hide();
			timer=setTimeout("trocaLogos(2)", 5000)
		}else{
			$('.btGrupoSantander').hide();
			$('.btReal').hide();
			$('.btSantander').fadeIn("slow");
			timer=setTimeout("trocaLogos(0)", 5000)
		}
	}
	timer=setTimeout("trocaLogos()", 5000)

//Funcao para abrir/fechar perguntas frequentes
function abreAbas(objeto){
	var objeto2 = objeto + 'Class';
	if($('#'+objeto).css('display')=='none'){
		$('#'+objeto).slideDown();
		$('#'+objeto2).addClass('boxPerguntaContentSetaOpen');
	}else{
		$('#'+objeto).slideUp();
		$('#'+objeto2).removeClass('boxPerguntaContentSetaOpen');
	}
}

function meuTalentoComent(objeto, status, link, id){
	var objeto2 = objeto + 'Alert';
	
	if(status == 0){
		$('#'+objeto2).hide();
	}else if(status == 1){
		$.post(link,
                {id: id},
                function(data){
                }
        );
		
		$('#'+objeto).hide();
		$('#'+objeto2).hide();
		
	}else{
		$('#'+objeto2).fadeIn("slow");			
	}
}

// fun��o carregar combos xml
$.fn.populateCombo = function(to,initialPath,file,xmlNode,typeText,typeValue,selectedValue){
	$(this).bind('change',function(){
		
		var xmlPath = '';
		switch(xmlNode){
			case 'city':
				xmlPath = initialPath + '/cities/'+ this.value.toLowerCase()+file;
				typeValue = 'name';
				break;
			case 'state':
				xmlPath = initialPath + this.value.toLowerCase() + file;
				break;
				
		}
		
		$(to).find('option')[0].title=$(to).find('option')[0].text;
		$(to).find('option')[0].text = 'Carregando...';

		$(to).find('option').each(function(i){
			if(i>0)$(this).remove();
		});
		$(to).attr('disabled','disabled');
		
		if (jQuery.trim(this.value) == '') {
			$(to).find('option')[0].text=$(to).find('option')[0].title;
			return false;
		};
		
		ajaxPopulate(to,xmlPath,xmlNode,typeText,typeValue,selectedValue);
		//$(this).unbind('change');
	});
	
};

ajaxPopulate = function (to,xmlPath,xmlNode,typeText,typeValue,selectedValue){
	if(typeText==undefined || typeText=='')typeText='name';
	if(typeValue==undefined || typeValue=='')typeValue='abbr';
	if(selectedValue==undefined || selectedValue=='')selectedValue='';
	
	$.ajax({
		url: xmlPath,
		success: function(returnXML){
			if ($(to).find('option').length == 1) {
				$(returnXML).find(xmlNode).each(function(){
 					$(to).append('<option value="' + $(this).attr(typeValue) + '" '+ (($(this).attr(typeValue) == selectedValue) ? 'SELECTED' : '') +'>' + $(this).attr(typeValue) + '<\/option>');
				});
			}
			$(to).removeAttr('disabled');
		}
	});
	$(to).find('option')[0].text=$(to).find('option')[0].title;
	
};

ajaxPopulate2 = function (to,xmlPath,xmlNode,typeText,typeValue,selectedValue){
	if(typeText==undefined || typeText=='')typeText='name';
	if(typeValue==undefined || typeValue=='')typeValue='abbr';
	if(selectedValue==undefined || selectedValue=='')selectedValue='';
	
	xmlPath = xmlPath.toLowerCase();
	
	$.ajax({
		url: xmlPath,
		success: function(returnXML){
			if ($(to).find('option').length == 1) {
				$(returnXML).find(xmlNode).each(function(){
 					$(to).append('<option value="' + $(this).attr(typeText) + '" '+ (($(this).attr(typeText) == selectedValue) ? 'SELECTED' : '') +'>' + $(this).attr(typeText) + '<\/option>');
				});
			}
			$(to).removeAttr('disabled');
		}
	});
	$(to).find('option')[0].text=$(to).find('option')[0].title;
	
};

// regulamento
showOption = function(info){
	$('.textRegulamento .box').hide();
	$('#'+info).fadeIn('slow');
	$('.regulaMenu li').removeClass('on');
	$('.regulaMenu li.'+info).addClass('on');
}
hideItens = function(objeto){
	$('#'+objeto).hide();
}

// inscricoes musica
showOptions = function(status){
	if(status == '1'){
		$('.openOptions').show();
		$('.cbanda').val('');
	}else{
		$('.openOptions').hide();
		$('.cbanda').val('none');
	}
}


showDescreva = function(obj,target){
	if ($('#'+obj).attr('checked')){
		$('.'+target).css('display','block');
	}else{
		$('.'+target).css('display','none');
	}
}

showDescrevaForRadio = function(objeto, status){
	if(status == '1'){
		$('.'+objeto).css('display','block');
	}else{
		$('.'+objeto).css('display','none');
	}
}

// inscricoes instituições
showOptionsIsntituicoes = function(status){
	if(status == '1'){
		$('#extraInfo').css('display','block');
	}else{
		$('#extraInfo').css('display','none');
	}
}

// inscricoes instituições
showOptionsConselho = function(status){
	if(status == '1'){
		$('#conselhoMunicipal').css('display','block');
	}else{
		$('#conselhoMunicipal').css('display','none');
	}
}

// querystring
function getQueryVariable(variable) {
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i=0;i<vars.length;i++)  {
		var pair = vars[i].split("=");
		if (pair[0] == variable) {
			return pair[1];
		}
	} 
}

// detalhes abas
showAba = function(status){
	$('li.abaVejaComentarios, li.abaComenteTrabalho, li.abaEnvieAmigo, li.abaEnvieComentario, li.trabalhoDownloadBox').removeClass('on');
	$('div.abaEnvieAmigoOk, div.abaEnvieAmigo, div.abaEnvieComentario, div.abaEnvieComentarioOk, div.trabalhoDownloadBox').hide();
	$('li.'+status).addClass('on');
	$('div.'+status).fadeIn('slow');
}

// post do grava comentario
function gravar_comentario(link, nome, email, optin) {
	$.post(link,
            {ccomment: $('#ccomment').val(), wrk_id: $('#wrk_id').val(), nome: nome, email: email, optin: optin },
            function(data){
            	$('#abaEnvieComentario').hide();
            	$('#abaEnvieComentarioOk').html(data);
            	$('#abaEnvieComentarioOk').fadeIn("slow");
            }
    );
    return false;
}

function gravar_comentario_blog(link, nome, email, art_id) {
	$.post(link,
            {ccomment: $('#ccomment').val(), nome: nome, email: email, art_id: art_id },
            function(data){
            	$('#abaEnvieAmigo').hide();
            	//$('#abaEnvieAmigoOk').html(data);
            	$('#abaEnvieAmigoOk').fadeIn("slow");
            }
    );
    return false;
}

function rssAlert(status) {
	if (status){
		$('#rssBoxAlert').fadeIn("slow");
	}else{
		$('#rssBoxAlert').fadeOut("slow");
	}
}

// post indique o trabalho a um amigo
function indique_amigo(link) {
	$.post(link,
            {abaSeuNome: $('#abaSeuNome').val(),abaSeuEmail: $('#abaSeuEmail').val(),abaAmigoNome: $('#abaAmigoNome').val(),abaAmigoEmail: $('#abaAmigoEmail').val(), wrk_id: $('#wrk_id').val(), art_id: $('#art_id').val(), sup_id: $('#sup_id').val() },
            function(data){
            	$('#abaEnvieAmigo').hide();
            	$('#abaEnvieAmigoOk').html(data);
            	$('#abaEnvieAmigoOk').fadeIn("slow");
            }
    );
    return false;
}

//post indique o trabalho a um amigo
function indique_amigo_blog(link) {
	$.post(link,
            {abaSeuNome: $('#abaSeuNome').val(),abaSeuEmail: $('#abaSeuEmail').val(),abaAmigoNome: $('#abaAmigoNome').val(),abaAmigoEmail: $('#abaAmigoEmail').val(), art_id: $('#art_id').val() },
            function(data){
            	$('#formEnvieAmigo').hide();
            	//$('#formEnvieAmigoOk').html(data);
            	$('#formEnvieAmigoOk').fadeIn("slow");
            }
    );
    return false;
}

//post indique o trabalho a um amigo
function envie_amigo(link) {
	$.post(link,
            {abaSeuNome: $('#abaSeuNome').val(),abaSeuEmail: $('#abaSeuEmail').val(),abaAmigoNome: $('#abaAmigoNome').val(),abaAmigoEmail: $('#abaAmigoEmail').val(),wrk_id: $('#wrk_id').val() },
            function(data){
            	$('#meuTalentoBox').hide();
            	$('#meuTalentoBoxOk').html(data);
            	$('#meuTalentoBoxOk').fadeIn("slow");
            }
    );
    return false;
}

// inscricoes musica
showAllComents = function(status){
	if(status == 'yes'){
		$('.btAbreComentarios').css('display','none');
		$('.paginacao, .btFechaComentarios').css('display','block');
	}else{
		$('.btFechaComentarios, .paginacao').css('display','none');
		$('.btAbreComentarios').css('display','block');
	}
}

enterFunction = function(){
	selected = $("#cquantosgrupo").val();
	var entraTxt = "";
	for(i = 1; i<=selected; i++){
		entraTxt += '<div class="item"><div class="numeroInscrito">'+ i +'</div><div class="cinquentaPx"><label for="cnameBanda'+ i +'"><span class="redAst">*</span>Nome completo:</label><br /><input id="cnameBanda'+ i +'" name="cnameBanda'+ i +'" class="required" /><span class="dica"><span class="dica2">Digite o nome completo do integrante.</span></span></div><div class="cinquentaPx"><label for="ccpfBanda'+ i +'"><span class="redAst">*</span>CPF:</label><br /><input id="ccpfBanda'+ i +'" name="ccpfBanda'+ i +'" class="required" /><span class="dica"><span class="dica2">Digite o CPF do integrante.</span></span></div><div class="cinquentaPx"><label for="cemailBanda'+ i +'"><span class="redAst">*</span>E-mail:</label><br /><input id="cemailBanda'+ i +'" name="cemailBanda'+ i +'" class="required email" /><span class="dica"><span class="dica2">Digite o e-mail do integrante.</span></span></div></div>';
	}
	$("#entra").html(entraTxt);
	for(i = 1; i<=selected; i++){
		$("#ccpfBanda"+i).mask("999.999.999-99");
	}
	hintFunc();
}

enterQuantidadeFunction = function(){
	selected = $("#cinfquant").val();
	var entraTxt = "";
	for(i = 1; i<=selected; i++){
		entraTxt += '<div class="cinquentaPx"><label for="cnomeinst'+ i +'"><span class="redAst">*</span>Nome da instituição:</label><br /><input id="cnomeinst'+ i +'" name="cnomeinst'+ i +'" class="required" maxlength="255" /><span class="dica"><span class="dica2">Coloque o seu endereço de e-mail. Assim, podemos informar você sobre todas as atualizações do concurso.</span></span></div><div class="cinquentaPx telefoneStyle opcionaisInscrito"><label for="ctelefoneInst'+ i +'"><span class="redAst">*</span>Telefone para contato:</label><br /><input id="cdddInst'+ i +'" name="cdddInst'+ i +'" class="ddd required" onkeypress="return DFonlyThisChars(true,false,null,event)" onkeyup="DFchangeField(this,event,1)" maxlength="2" value=""  /><span class="dica"><span class="dica2">Preencha o número do seu DDD.</span></span><input id="ctelefoneInst'+ i +'" name="ctelefoneInst'+ i +'" class="tel required" maxlength="9" value=""  /><span class="dica"><span class="dica2">Preencha o número do seu telefone.</span></span></div><div class="cinquentaPx"><label for="cemailinst'+ i +'"><span class="redAst">*</span>E-Mail:</label><br /><input id="cemailinst'+ i +'" name="cemailinst'+ i +'" maxlength="255" class="required email" /><span class="dica"><span class="dica2">Coloque o seu endereço de e-mail. Assim, podemos informar você sobre todas as atualizações do concurso.</span></span></div><br />';
	}
	$("#entra").html(entraTxt);
	for(i = 1; i<=selected; i++){
		$("#ctelefoneInst"+i).mask("99999999");
	}
	hintFunc();
}
/* manter sinergia com o partial paginatorTotals.phtml */
function isWinner(){}

// checkboxes
;(function($) {
 
/*
 * Toggle all checkboxes contained within a form
 */
$.fn.toggleCheckboxes = function(filter, returnChecked){
	filter = filter || "*";
	returnChecked = returnChecked || false;
	var returnWhat = $([]);
	//desapego
	var principal = $('#chbx-user');
	(principal.is(':checked'))? principal.removeAttr('checked'):principal.attr('checked','checked');
	this.each(
		function(){
			var checked = $("input[type=checkbox]", this).filter(filter).each(
				function(){
					this.checked = !this.checked;
				}
			).filter(":checked");
			returnWhat = checked;
		}
	);
	if(!returnChecked){
		returnWhat = this;
	}
	return returnWhat;
};

/*
 * Check all checkboxes contained within a form
 */
$.fn.checkCheckboxes = function(filter, returnChecked){
	filter = filter || "*";
	returnChecked = returnChecked || false;
	var returnWhat = $([]);
	this.each(
		function(){
			var checked = $("input[type=checkbox]", this).filter(filter).each(
				function()
				{
					this.checked = true;
				}
			).filter(":checked");
			returnWhat = checked;
		}
	);
	if(!returnChecked){
		returnWhat = this;
	}
	return returnWhat;
};

/*
 * UnCheck all checkboxes contained within a form
 */
$.fn.unCheckCheckboxes = function(filter, returnUnChecked){
	filter = filter || "*";
	returnUnChecked = returnUnChecked || false;
	var returnWhat = $([]);
	this.each(
		function(){
			var unChecked = $("input[type=checkbox]", this).filter(filter).each(
				function()
				{
					this.checked = false;
				}
			).filter(":not(:checked)");
			returnWhat = unChecked;
		}
	);
	if(!returnUnChecked){
		returnWhat = this;
	}
	return returnWhat;
};

/*
 * Makes checkboxes behave like a radio button group
 *   i.e. only one can be selected at a time
 */
$.radioCheckboxGroup = function(name, filter){
	filter = filter || "*";
	var expression = "input[type=checkbox]";
	if(name){
		expression += "[name=" + name + "]"
	}
	var x = $(expression).filter(filter);
	x.click(
		function(){
			// uncheck every other box with the same name
			x.not(this).each(
				function()
				{
					this.checked = false;
				}
			).end();
		}
	);
};

})(jQuery);


// apelido url
function trocaURL(){
	$('#textURLfinal').html('Sua URL será http://www.talentosdamaturidade.com.br/'+$('#capelito').val());
}
