// JavaScript Document

jQuery.preloadImages = function() {
  for(var i=0; i<arguments.length; i++)   {
    jQuery("<img>").attr("src", arguments[i]);
  }
}

// Popup home
jQuery.somepop = function() {
	$("#popmsg").slideUp("slow");
}
jQuery.surgepop = function() {
	$("#popmsg").slideDown("normal");
}

jQuery.createpopup = function() {
	var arquivo = arguments[0];
	var alvo = arguments[1];
	var oiframe ='<div id="popmsg" class="popmsg"><div class="barracmd"><a href="#" id="lk_fechapop">[X] Fechar</a></div>\n'
				+'<iframe frameborder="0" width="100%" height="90%" id="fr_msg" src="'+arquivo+'"></iframe></div>\n';
   $("#"+alvo).append(oiframe);
   $("#lk_fechapop").bind("click", $.somepop )
   var tempo1 = setTimeout($.surgepop, 1000);
   var tempo2 = setTimeout($.somepop, 20000);
	   
}

$(function() {

	//$.preloadImages("img/ani_home/foto0.jpg","img/ani_home/foto1.jpg","img/ani_home/foto2.jpg","img/ani_home/foto3.jpg");

	// fix for target="_blank"
	var w = 900; var h = 650;
	var ww = $(window).width(); 
	var wh = $(window).height();
	
	if(wh<h) {
		w = ww; 
		h = wh;
	}
	
	$("a[rel='external']").click(function(){
		window.open($(this).attr("href"), 'janela','scrollbars=yes,resizable=yes,width='+w+',height='+h);
		return false;
	});
	
	// Verifica se div do popup existe e chama o popup
	if($("#cont_pop").length > 0) $.createpopup('pop_up.php','cont_pop');
	
	// Popu-up arrastável
	$("#popmsg").draggable();

});

