


/**
 * TROCA DE BACKGROUND NA HOME
 * 
 * Ativado pelo flash da home, troca a imagem de background do fundo (body)
 */
function swapView(currentView){
	// pegar url do template pelo href do css
	var lcss = document.getElementById('style_css').href;
	var fim = lcss.lastIndexOf('/');
	var css = lcss.substring(0, fim + 1) + "css/";
	
	if(currentView == 'arte_1'){img = 'arte_1.gif';pos = '-250px';cor = 'transparent';repeat = 'repeat';}
	else if(currentView == 'arte_2'){img = 'arte_2.png';pos = '0';cor = 'transparent';repeat = 'repeat';}
	else if(currentView == 'arte_3'){img = 'arte_3.jpg';pos = '0';cor = '#F0F0F0';repeat = 'no-repeat';}
	document.getElementsByTagName('body')[0].style.background = cor + ' url(' + css + img + ') ' + repeat + ' center ' + pos;
	createCookie('bg', currentView, 1);
}


jQuery(document).ready(function($){
	
	/**
	 * FORM DE UPLOAD
	 * 
	 * Verifica em looping se o usuário já fez o upload da imagem
	 */
	/*
	// esconde os elementos do formulário
	if( $('#uploadfiles_inline').length > 0 ){
		$('#tdomf_form1_send').hide();
		$('#recaptcha_widget_div').parent().hide();
		$('#content-title-tf').parent().hide();
		$('#iagree').parent().hide();
		$('#notifyme').parent().hide();
		// inicia a verificação em loop, por timeOut
		verify_upload();
	}
	
	// função loop que verifica o estado do form de upload, que fica em um iframe
	function verify_upload(){
		// identifica o iframe, crossbrowser
		objDoc = window.frames[ "uploadfiles_inline" ].document;
		// verifica a existência do formulário
		if( $(objDoc).contents().find('#tdomf_upload_inline_form').length > 0 ){
			// testa a existência do submit para apagar a imagem, ou seja, o upload foi feito co sucesso.
			// Mostra os elementos do form escondidos
			if( $(objDoc).contents().find('#tdomf_upload_inline_delete_all_1').length > 0 ){
				$('#tdomf_form1_send').show();
				$('#recaptcha_widget_div').parent().show();
				$('#content-title-tf').parent().show();
				$('#iagree').parent().show();
				$('#notifyme').parent().show();
			}
			// esconde os elementos caso a imagem seja apagada
			else{
				$('#tdomf_form1_send').hide();
				$('#recaptcha_widget_div').parent().hide();
				$('#content-title-tf').parent().hide();
				$('#iagree').parent().hide();
				$('#notifyme').parent().hide();
			}
		}
		else{
			$('#tdomf_form1_send').hide();
			$('#recaptcha_widget_div').parent().hide();
			$('#content-title-tf').parent().hide();
			$('#iagree').parent().hide();
			$('#notifyme').parent().hide();
		}
		// retorna o loop ao início
		setTimeout(verify_upload, 200);
	}
	*/
	
	/**
	 * LIGHTBOX
	 * 
	 * Lightbox para a seção de votação
	 * Plugin jquery lightbox requerido ( http://leandrovieira.com/projects/jquery/lightbox/ )
	 */
	// pegar url do template pelo href do css
	var lcss = document.getElementById('style_css').href;
	var fim = lcss.lastIndexOf('/');
	var css = lcss.substring(0, fim + 1) + "css/";
	$('.imagem_vote').lightBox(
			{
			imageLoading:css + 'lightbox-ico-loading.gif',
			imageBtnClose:css + 'lightbox-btn-close.gif',
			imageBtnPrev:css + 'lightbox-btn-prev.gif',
			imageBtnNext:css + 'lightbox-btn-next.gif',
			txtImage:'Imagem',
			txtOf:'de',
			imageBlank:css + 'lightbox-blank.gif'
			}
		);
	
	/**
	 * VOTES UPDATE
	 * 
	 * Verifica a atualização dos votos
	 * Plugin jquery colors, chamado no functions.php, via wp_enqueue_script('jquery-color');
	 */
	/*
	// Verifica se está na página de votação e inicia o loop de verificação
	if( $('#vote_list .gdsr_rating_as').length > 0 ){
		$('.gdsr_rating_as').each(function(){
			// separa a ID do post votado
			var post_id = $(this).attr('id').replace('gdr_stars_a','');
			$('#vote_item_' + post_id + ' .imagem_vote' ).append('<div class="item_vote" id="item_vote_' + post_id + '"></div>');
		});
		verify_votes_update();
	}
	function verify_votes_update(){
		// identifica cada post aberto à votação, através do holder do starRating .gdsr_rating_as
		$('.gdsr_rating_as').each(function(){
			// quando um post é votado, o holder do starRating é esvaziado
			if( $(this).html() == '' ){
				// identifica a raiz do site. Necessário para utilização em localhost/online
				var home = $('#url_home').attr('href');
				// separa a ID do post votado
				var post_id = $(this).attr('id').replace('gdr_stars_a','');
				
				// consulta via ajax os dados atualizados do post e atualiza
				$("#votes_data_" + post_id).load(home+'ajax-load/?id='+post_id, {id: home}, function(){
					// mostra o resultado em fading
					$("#ratingsfor_" + post_id).animate({ backgroundColor: "white" }, 1000);
					$("#votesfor_" + post_id).animate({ backgroundColor: "white" }, 1000);
				});
				// adiciona codigo html para burlar o loop
				$(this).html('<span style="display:none">_</span>');
				$('#item_vote_' + post_id).remove();
			}
		});
		// retorna o loop ao início
		setTimeout(verify_votes_update, 500);
	}
	*/
	
	/**
	 * VOTES ALERT
	 * 
	 * Exibe mensagem caso a pessoa tente votar, mas não esteja logada
	 */
	/*
	if( $('.box_aviso').length > 0 ){
		$('.ratingblock').toggle(
			function(){
				$(this).find('.box_aviso:first').fadeIn();
			},
			function(){
				$(this).find('.box_aviso:first').fadeOut();
			}
		)
		
		$('.ratingblock').css('cursor','pointer');
		$('.box_aviso a').click(function(){
			createCookie('vote_url', window.location.href , 1);
			//var home = $('link[rel=index]').attr('href');
			window.location = $(this).attr('href');
			//alert( readCookie('vote_url') );
			//return false;
		});
	}
	*/
	
});



// cookie functions http://www.quirksmode.org/js/cookies.html
function createCookie(name,value,days){
	if (days){
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name){
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++){
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name){
	createCookie(name,"",-1);
}
// /cookie functions