﻿$(document).ready(efeitos);

// CHAMA AS DEMAIS FUNCOES
function efeitos(){
	form_submit_ajax();
	//expand_img();
	add_focus();
	//no_border();
	//link_externo();
	popup();
};

//SLEEP
function sleep(tempo){
	var now = new Date();
	var exitTime = now.getTime() + tempo;
	while (true){
		now = new Date();
		if (now.getTime() > exitTime) return;
	}
}

// SUBMIT FORM
function form_submit_ajax(){
	$('#bt_pagar').click(function(event){
		var button = $(this);
		var form   = $('#form_pagamento');
		var action = $(form).attr('action');
		$(button).attr('value', 'Por favor, aguarde...').attr('title', 'Aguarde').addClass('loading').blur();
		$.post(action, {ajax: 'true'}, function(data){
			if(data == 'liberado'){
				$(form).attr('action', 'https://pagseguro.uol.com.br/security/webpagamentos/webpagto.aspx').submit();
			}else{
				window.location.reload();
			}
		});
		event.preventDefault();
	})
};

//EFEITO AMPLIAR IMG
function expand_img(){
	$("a[@href*=.jpg],a[@href*=.gif]").each(function(event){
		this.onclick = function(){
			return hs.expand(this, {align:'center'})
		};
		event.preventDefault();
	})
};

// FOCUS NOS CAMPOS
function add_focus(){
	$('.searchform input').focus(function(){
		$(this).attr('value','');
	});
	$('.searchform input').blur(function(){
		var input = $(this).attr('value');
		if (input == ''){  
			$(this).attr('value','Localizar conteúdo');
		}
	});
};

// NO BORDER CLICK IE7
function no_border() {
	$('a').focus(function() {
		$(this).blur();
	})
};

//TARGET LINKS EXTERNOS
function link_externo(){
	$("a:not([@href*=lilarte])").not("[href^=#]").addClass("externo").attr({ target: "_blank" });
};

//POPUP
function popup(){
	$('.page-item-10 a').popupWindow({ 
		//windowURL:'http://code.google.com/p/swip/', 
		//windowName:'swip',
		//centerBrowser:1,
		//height:500, 
		//top:50, 
		//left:50 
		width: 550,
		centerScreen: 1
	})
}