$.ajaxSetup({ scriptCharset: "iso-8859-1" , contentType: "application/x-www-form-urlencoded; charset=iso-8859-1"});


var _iMsgCallbackI = null;
var _iMsgCallbackState;

function _iMsgCallback() {
	_iMsgCallbackI = setInterval(function () {
		if(_iMsgCallbackState) {
			$("#iMsg").animate({opacity: .4}, 400);			
		} else {
			$("#iMsg").animate({opacity: 1}, 400);
		}
		
		_iMsgCallbackState = !_iMsgCallbackState;
	}, 1000);
}

function setPValue(val, mx, desc, obj, al) {
	val = val < 0 ? 0 : val;
	
	if(al) {
		if(val <= (mx / 4)) {
			$(".progFill", $(obj)).css("background-color", "#FF3300");
		} else if (val <= (mx / 2)) {
			$(".progFill", $(obj)).css("background-color", "#FF9900");
		}
	}
	
	$(".progFill", $(obj)).animate(
		{width: (($(obj).width() / mx) * val)}, 500
	);
	
	$(".progText", $(obj)).html(desc + (desc ? ":&nbsp;" : "") + val);
}

function setPValue2(val, mx, desc, obj, al) {
	val = val < 0 ? 0 : val;
	
	if(al) {
		if(val <= (mx / 4)) {
			$("#p", $(obj)).css("background-color", "#FF3300");
		} else if (val <= (mx / 2)) {
			$("#p", $(obj)).css("background-color", "#FF9900");
		}
	}
	
	var _nw = ($(obj).width() / mx) * val;
	var _ow = $(obj).width();
	
	$("#p", $(obj)).animate(
		{width: (_nw > _ow ? _ow : _nw)}, 500
	);
	
	$("#t", $(obj)).html(desc + (desc ? ":&nbsp;" : "") + val);
}

function isBrowserClosed(e) {
	if(navigator.userAgent.indexOf("MSIE") != -1) { // IE
		var browserWindowWidth = 0;
		var browserWindowHeight = 0;
	
		// gets the width and height of the browser window
		if (parseInt(navigator.appVersion) > 3) {
			if (navigator.appName == "Netscape") {
				browserWindowWidth = window.innerWidth;
				browserWindowHeight = window.innerHeight;
			}
	
			if (navigator.appName.indexOf("Microsoft") !=- 1) {
				browserWindowWidth = top.window.document.body.offsetWidth;
				browserWindowHeight = top.window.document.body.offsetHeight;
			}
		}
	
		var r = (event.clientY < 0 && event.screenX > (browserWindowWidth - 25)) ? true : false;
		
		if(!r) {
			if(window.event.clientY < 0) {
				return true;
			} else {
				return false; // WARN: CTRL + W goes here	
			}
		} else {
			return r;
		}
	} else { // FF
		if(!window.innerWidth) {
			return true;	
		} else {
			return false;	
		}
	}
}

function logoff() {
	if(typeof(_isPVP) == "undefined") _isPVP = false;
	
	if(_isPVP) {
		$.ajax({
			url: 'index.php?acao=dojo_batalha_lutar',
			type: 'post',
			data: {action: 2},
			dataType: 'script',
			async: false,
			success: function () {
				location.href = "?acao=logoff";
			},
			error: function () {
				location.href = "?acao=logoff";
			}
		});	
	} else {
		location.href = "?acao=logoff";
	}
}

function sairVila() {
	$.ajax({
		url: '?acao=mapa_vila&e',
		type: 'get',
		dataType: 'script',
		async: false
	});
}

function mapaVila() {
	$.ajax({
		url: '?acao=mapa_vila&v',
		type: 'get',
		dataType: 'script',
		async: false
	});
}

$(window).scroll(function (event) {
						   
	if($(window).scrollTop() > 340) {
		$("#pIcones").stop().animate({top: $(window).scrollTop() - 200 }, 500);
		
		//$("#pIcones").css("top", $(window).scrollTop() - 200);
	} else {
		$("#pIcones").stop().animate({top: 120 }, 500);
	}
});

$(document).ready(function () {
	$("#pIcones .i").css("opacity", .2);
});

$("#pIcones .i").live('mouseover', function (event) {
	$(this).css("opacity", 1);
	
	$(".t", $(this)).show().css("opacity", .8); //.bg(10);
})
			.live('mouseout', function (event) {
	$(this).css("opacity", .2);

	$(".t", $(this)).hide();
	$(".invetoryDetailPopup").remove();
});