$(document).ready(function(){

    $("#commentForm").validate();

	$.fn.popOpen = function(){
		
		popID = $(this).attr('rel'); 
		popURL = $(this).attr('href'); 
		
		
		query= popURL.split('?');
		dim= query[1].split('&');
		popWidth = dim[0].split('=')[1]; 
		
		
		$('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close"><img src="imagens/close_pop.png" class="btn_close" title="Fechar" alt="Fechar" /></a>');
		
		var popMargTop = ($('#' + popID).height() + 80) / 2;
		var popMargLeft = ($('#' + popID).width() + 80) / 2;
		
		$('#' + popID).css({ 
			'margin-top' : -popMargTop,
			'margin-left' : -popMargLeft
		});
		
		$('body').append('<div id="fade"></div>'); 
		$('#fade').css({'filter' : 'alpha(opacity=55)'}).fadeIn(); 
		
	};

	
	$('a.poplight[href^=#]').click(function() {
		$(this).popOpen(); 
		return false;
	});


var onealert = $.cookie('seeMeOnce');

if (onealert != 'viewed') {
setTimeout(function(){
$('a.poplight[href=#?w=350]').popOpen(); //Run popOpen function once on load
 },50000);
};
	
	$('a.close, #fade').live('click', function() {
		
	  	$('#fade , .popup_block').fadeOut(); 
		$('#fade').remove();
        $.cookie('seeMeOnce', 'noviewed'); //codigo p cookie
		return false;
	});

	popOpen
	
});
