/*MODAL*/
var urlModal;

function openModal(url){
	/*URL MODAL*/
	urlModal = url;
			
	$J('.view_modal').remove();
	
	/*CREATE ELEMENTS*/
	$J('body').append('<img src="/img/load.gif" width="88" height="78" alt="Carregando..." class="load" /><div class="bg_modal"></div><div class="view_modal"></div>');
	$J('.bg_modal').width($J('html')[0].scrollWidth).height($J('html')[0].scrollHeight);
	
	/*OPACITY*/
	$J('.view_modal').css('opacity', 0);
	$J('.bg_modal').css('opacity', 0);
	
	/*SELECTS HIDE*/
	$J('select').css('visibility', 'hidden');

	/*SHOW BACKGROUND*/
	$J('.bg_modal').fadeTo('fast', 0.8, function(){
		$J('.view_modal').load(url, function(){
			/*REMOVE LOAD*/
			$J('.load').remove();
			
			/*CENTRALIZE MODAL*/
			$J('.view_modal').css({marginTop: -$J('.view_modal').height()/2 + 'px', marginLeft: -$J('.view_modal').width()/2 + 'px'});
			
			/*MODAL HIDE*/
			$J('.view_modal').fadeTo('fast', 1);
			
			/*CLOSE MODAL*/
			$J("a[@rel='modal_close']").click(function(){
				closeModal();
				return false;
			})
		})
	})
}

/*CLOSE MODAL*/
function closeModal(){
	/*HIDE MODAL*/
	$J('.view_modal').fadeTo('fast', 0, function(){
		$J(this).remove();
	})
	
	/*HIDE BACKGROUND*/
	$J('.bg_modal').fadeTo('fast', 0, function(){
		$J(this).remove();

		/*SHOW SELECT*/
		$J('select').css('visibility', 'visible');
	})
}

/*INIT MODAL*/
function initModal(){
	$J("a[@rel='modal']").click(function(){
		openModal($J(this).attr('href'));
		return false;
	})
}

/*GET QUERY VARIABLE*/
function getQueryVariable(url, variable){
	var vars = url.substring(0).split('?');
	for(var i = 0; i < vars.length; i++){
		if(vars[i].split("=")[0] == variable){
			return vars[i].split('=')[1];
		}
	}
}

/*SIFR*/
function initSifr(){
	if(sIFR != null && sIFR.replaceElement != null){
		sIFR.replaceElement('.titulo h2', '/swf/helvetica.swf', '#FFFFFF', '#FFFFFF', 'transparent', 'transparent', 0, 0, 0, 0);
		sIFR.replaceElement('.titulo h3', '/swf/helvetica.swf', '#000000', '#000000', 'transparent', 'transparent', 0, 0, 0, 0);
		
		sIFR.replaceElement('h3.subtitulo', '/swf/bliss.swf', '#CCCC99', '#CCCC99', 'transparent', 'transparent', 0, 0, 0, 0);
		
		$J('.titulo h2, .titulo h3, h3.subtitulo').css('visibility', 'visible');
	}
}

/*COPY HEIGHT*/
function copyHeight(){
	var heights = [];

	for(var i = 0; i < arguments.length; i++)
		heights.push($J(arguments[i]).height());

	hT = heights.sort(function(a, b){ return a - b }).reverse()[0];

	for(var i = 0; i < arguments.length; i++)
		$J(arguments[i]).height(hT);
}

function addAmigo(){
	var re = /(?:\w*\[)(\d+)(?:\]\[\w*\])/i
	
	  $J(".amigo:last").after($J(".amigo:last").clone())
	  
	  var x = $J(".amigo:last").find("input");
	  
	  $J(".amigo:last").find("input").attr("name", function(arr){ 
		
		var str = x.eq(arr).attr("name");
		$J(".amigo:last").find("input").eq(0).val("Nome do amigo*:");
		$J(".amigo:last").find("input").eq(1).val("Email do amigo*:");
		
		return str.replace(/\d+/, eval(str.match(re)[1]) + 1);     
	});
}

function pop(x,n,w,h,s) {
	var l = ( (window.screen.width  - w) / 2 );
	var t = ( (window.screen.height - h) / 2 );
	janelinha = window.open(x,n,'leftmargin=0,topmargin=0,marginheight=0,marginwidth=0,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars='+s+',resizable=no,top='+t+',left='+l+',screenX='+l+',screenY='+t+',copyhistory=no,height='+h+',width='+w+'');
	janelinha.focus();
}