// JavaScript Document
function docReady() {
	/*
	$("#body").dropShadow({
						top:0,
						left:0,
						blur:9,
						opacity:.5
						});
	*/
	$("#body").shadowOn({imageset:'89'});
	searchPsico();
	regShot();
	scrollMenu();
}
function searchPsico() {
	// PESQUISAR
	$("#pesquisar").corner("5px");
	$("#search").dropShadow({
						  top:0,
						  left:0
						  });
	$("#search").keypress(function(event) {
									  if (event.keyCode == undefined || event.keyCode == '13') {
										  event.preventDefault();
										  searchSite();
									  }
									  });
}
function searchSite() {
	var co = $.trim($("#search").val());
	if (co.length > 0) {
		$.fancybox.showActivity();
		$.ajax({
		   url: "procurar.php?"+Math.random(),
		   cache: false,
		   type: "POST",
		   data: ({procurar:co}),
		   success: function(data) {
			   $.fancybox({content:data});
			},
		   error: function(data) {
			   $.fancybox({content:"Erro: "+data.responseText});
		   }
		});
	}
}
function regShot() {
	$("#reg").snapReg("#body");
	$("#reg").corner("top");
	$("#orelhaReg1").orelhaRight("#reg");
	$("#orelhaReg2").orelhaLeft("#reg");
}
function scrollMenu() {
	var mo = $("#menuouter");
	var m  = $("#menu");
	mo.css("height",m.outerHeight() + 70 + "px");
	mo.css("width", $("#body").outerWidth() + 35 + "px"); // center
	mo.css("left", "40px"); // center
	mo.css("top", "255px");
	
	m.css("left", mo.offset().left + "px"); // center
	m.css("top", mo.offset().top + mo.outerHeight()/2 - m.outerHeight()/2 + "px");
	
	mo.corner();
	m.corner("right");
	m.dropShadow({top:1,left:0});
}
// Animar para o centro
/*
var scrolling=false;
$(window).scroll( function() {
						   if (!scrolling) {
							   scrolling=true;
							   $("#menuouter").animate({top: $(window).scrollTop() + ($(window).height()/2 - $("#menuouter").outerHeight()/2) + "px"}, function() { scrolling=false; });
						   }
						   } );
*/
jQuery.fn.orelhaRight = function (b) {
	b=$(b);
	var h = b.outerHeight()/2;
	this.css("height", h+"px");
	this.css("width",h+"px");
	this.css("top", (b.offset().top + b.outerHeight()) - this.outerHeight() + "px" );
	this.css("left", b.offset().left + b.outerWidth() + "px");
	this.corner("bevel br "+h+"px");
	return this;
};
jQuery.fn.orelhaLeft = function (b) {
	b=$(b);
	var h = b.outerHeight()/2;
	this.css("height", h+"px");
	this.css("width",h+"px");
	this.css("top", (b.offset().top + b.outerHeight()) - this.outerHeight() + "px" );
	this.css("left", b.offset().left - h + "px");
	this.corner("bevel bl "+h+"px");
	return this;
};
jQuery.fn.orelhaLeftb = function (b, top) {
	if (top==undefined) {
		top=0;
	}
	b=$(b);
	var h = parseInt(b.outerHeight()/2);
	this.css("height", h+"px");
	this.css("width",h+"px");
	this.css("top", top+b.offset().top + b.outerHeight() + "px");
	this.css("left", b.offset().left + "px");
	this.corner("bevel bl "+h+"px");
	return this;
};
jQuery.fn.orelhaRightb = function (b,top) {
	if (top==undefined) {
		top=0;
	}
	b=$(b);
	var h = parseInt(b.outerHeight()/2);
	this.css("height", h+"px");
	this.css("width",h+"px");
	this.css("top", top+b.offset().top + b.outerHeight() + "px");
	this.css("left", b.offset().left + b.outerWidth() - h + "px");
	this.corner("bevel br "+h+"px");
	return this;
};
jQuery.fn.snapReg = function (b) {
	b=$(b);
	this.css("top", b.offset().top + b.outerHeight() - this.outerHeight()/2 + "px");
	this.css("left", b.offset().left + b.outerWidth()/2 - this.outerWidth()/2 + "px");
    return this;
}
jQuery.fn.snapBlocoLeft = function (b,tam, top) {
	if (tam == undefined) {
		tam=10;
	}
	var blstr = b+"Bloco";
	var bl = $(blstr);
	bl.css("padding","0px");
	bl.css("top", this.offset().top + "px");
	bl.css("height", this.outerHeight() + "px");
	bl.css("left", this.offset().left - tam + "px");
	bl.css("width", tam+"px");
	$(b).orelhaLeftb(blstr,top);
	return this;
}
jQuery.fn.snapBlocoRight = function (b,tam, top) {
	if (tam==undefined) {
		tam=10;
	}
	var blstr = b+"Bloco";
	var bl = $(blstr);
	bl.css("padding","0px");
	bl.css("top", this.offset().top + "px");
	bl.css("height", this.outerHeight() + "px");
	bl.css("left", this.offset().left + this.outerWidth() + "px");
	bl.css("width", tam+"px");
	$(b).orelhaRightb(blstr,top);
	return this;
}

