var $=jQuery;
$(document).ajaxStart($.blockUI(blockUI_message)).ajaxStop($.unblockUI(blockUI_message));

jQuery(document).ready(function(){
	jQuery("#left object").attr("width","648");
	jQuery("#left object embed").attr("width","648");
	jQuery("#left img").each(function(){
		if(jQuery(this).width()>648) jQuery(this).attr("width","648");
	});
	jQuery('input[title!=""]').hint();
	jQuery('textarea[title!=""]').hint();
	//jQuery(".alignnone").parent().colorbox();
	//jQuery(".imported").parent().colorbox();
	//jQuery(".separator a").colorbox();
	//$("a[rel='example1']")
	jQuery(".post img").lazyload({ 
		placeholder : "images/grey.gif",
		effect : "fadeIn"
	});
	menuAnimate();
	navigation();
	$(".title a ,.comments-link, .navigation a, .link, #logo, .read-more, .comments-link, .comments-nro, .send, .contact").click(function(){defaultLoadMessage();});
});
var keyPressed=new Array();
function navigation(){
	var $prev = $("a[rel='prev']").attr("href");
	var $next = $("a[rel='next']").attr("href");
	
	$(document).keyup(function(e) {
		keyPressed = new Array(0);
	});
	$(document).keydown(function(e) {
		keyPressed.push(e.which);
		if(e.which==37 && $prev && checkRestrictElements()){
			defaultLoadMessage();
			window.location = $prev;
		}else if(e.which==39 && $next && checkRestrictElements()){
			defaultLoadMessage();
			window.location = $next;
		}
	});
}
function checkRestrictElements(){
	var el = jQuery(document.activeElement).filter(':focus').get(0);
	if(el==undefined) return true;
	if(el.tagName=="INPUT" || el.tagName =="TEXTAREA") return false;
}
function inArray(needle, haystack) {
    var length = haystack.length;
    for(var i = 0; i < length; i++) {
        if(haystack[i] == needle) return true;
    }
    return false;
}

var blockUI_message = { message: '<span class="load_ico"></span>Carregando',css: {
		fadeIn: 1000, 
		border: 'none', 
		padding: '15px', 
		backgroundColor: '#000', 
		'-webkit-border-radius': '10px', 
		'-moz-border-radius': '10px', 
		opacity: .8, 
		width:'200px',
		top:  ($(window).height() - 30) /2 + 'px', 
		left: ($(window).width() -200) /2 + 'px', 
		zIndex:999999,
		color: '#fff' 
	} };
function defaultLoadMessage(){
	if(inArray("16",keyPressed) || inArray("17",keyPressed)) return;
	$.blockUI(blockUI_message);
	
}
function addSwf(url,width,height){
	var location = $(this).parent();
	swfobject.embedSWF(url, location, width, height, "9.0.0", "expressInstall.swf");
}
function menuAnimate(){
	$(".the_menu .link").each(function(){
		var t = $("<div class='menu_follow'></div>");
		$(t).css("width",$(this).css("width"));
		$(t).css("left",$(this).css("left"));
		$(t).css("opacity",0);
		$(this).parent().append(t);
		if(!$(this).hasClass("active")){
				
			$(this).mouseover(function(){
					$(t).animate({
						opacity:1,
						top:"53px"
						},500);
				}).mouseout(function(){
					$(t).animate({
						opacity:0,
						top:"45px"
						},500);
				});
		}else{
			$(t).css("top","53px");
			$(t).css("opacity",1);
		}
		});
		
	//var l =  $(this).css("left");
	//var w = $(this).css("width");
	//document.title =l + " | " +w  ;
	
	//var $mf = $("#menu_follow");
	/*
	$mf.animate({
			left: l,
			width:w
		},"1").delay(500);
	*/
}
