startList = function() {
	if (document.all && document.getElementById) {
		navRoot = document.getElementById("nav");
		if (navRoot!=null) {
			for (i=0; i<navRoot.childNodes.length; i++) {
				node = navRoot.childNodes[i];
				if (node.nodeName=="LI") {
					node.onmouseover = function() {
						this.className+=" over";
					};
					node.onmouseout = function() {
						this.className=this.className.replace(" over", "");
					};
				}
			}
		}
	}

	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("owninv");
		if (navRoot!=null) {
			for (i=0; i<navRoot.childNodes.length && navRoot; i++) {
				node = navRoot.childNodes[i];
				if (node.nodeName=="LI") {
					node.onmouseover=function() {
						this.className+=" over";
					};
					node.onmouseout=function() {
						this.className=this.className.replace(" over", "");
					};
				}
			}
		}
	}

	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("achievment");
		if (navRoot!=null) {
			for (i=0; i<navRoot.childNodes.length && navRoot; i++) {
				node = navRoot.childNodes[i];
				if (node.nodeName=="LI") {
					node.onmouseover=function() {
						this.className+=" over";
					};
					node.onmouseout=function() {
						this.className=this.className.replace(" over", "");
					};
				}
			}
		}
	}

	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("battlewall");
		if (navRoot!=null) {
			for (i=0; i<navRoot.childNodes.length && navRoot; i++) {
				node = navRoot.childNodes[i];
				if (node.nodeName=="DIV") {
					node.onmouseover=function() {
						this.className+=" over";
					};
					node.onmouseout=function() {
						this.className=this.className.replace(" over", "");
					};
				}
			}
		}
	}

}

window.onload=startList;


/* Open popup centered */
function windowOpener(windowHeight, windowWidth, windowName, windowUri) {
	var centerWidth = (window.screen.width - windowWidth) / 2;
	var centerHeight = (window.screen.height - windowHeight) / 2;
	newWindow = window.open(windowUri, windowName, 'status=no,toolbar=no,location=no,menubar=no,directories=no,width=' + windowWidth + ',height=' + windowHeight + ',left=' + centerWidth + ',top=' + centerHeight);
	newWindow.focus();
	return newWindow.name;
}

function facebook_connect_redirectToLink(link) {
	window.location = link;
}

returnToErpk = function() {
	jQuery.post("import-contacts", {
			_token: $j('#_token').val(),
			type: "contacts"
			},
			function(data){
				try {
					childW.close();
					toggleInviteContainer(data);
				}
				catch(e) {;}
			}	);
}

function toggleInviteContainer(data) {
	try {
		$j('#invite_container').html(data);
		$j('#invite_container').fadeIn();
		$j('#findfriends').hide();
		$j('#findfriends_gmail').hide();
		$j('#loading').hide();
	}
	catch(e){;}
}
function Set_Cookie( name, value, expires, path, domain, secure ) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	//
	// /*
	// if the expires variable is set, make the correct
	// expires time, the current script below will set
	// it for x number of days, to make it for hours,
	// delete * 24, for minutes, delete * 60 * 24
	// */
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	 var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
	 ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
	 ( ( path ) ? ";path=" + path : "" ) +
	 ( ( domain ) ? ";domain=" + domain : "" ) +
	 ( ( secure ) ? ";secure" : "" );
}

function addEnergy() {
	try {
		var i = $j('#DailyConsumtionTrigger');
		var has_reset = i.hasClass('reset');
		i.removeClass();
		i.addClass('eat_food_wide');
		if (has_reset) {
			$j(".resetFoodContainer").hide();
			$j("#foodText").show();
			i.removeClass('reset');
		}
		i.addClass('energy');

		if (typeof(battleFX) != 'undefined'){
			closeNoFoodWarning();
			$j('#heal_btn').removeClass();
			$j('#heal_btn').addClass('food_btn');
			$j('#heal_btn').addClass('energy');
			$j('#heal_btn').attr('title', 'Consume Energy Bar');
		}

		$j('#DailyConsumtionTrigger strong').html("Eat");
		$j('#DailyConsumtionTrigger').attr("href", 'javascript:return false;');
	} catch(e) {;}
}

function removeEnergy() {
	try {
		$j('#DailyConsumtionTrigger').removeClass('energy');
		$j('#heal_btn').removeClass('energy');
	} catch(e) {;}
}

function applyFeedingEffects(data) {
	try {
		reset_has_food = data.has_food_in_inventory;
		var show_buy =  (data.has_food_in_inventory == 0 && data.food_remaining > 0);
		var show_warn = (data.food_remaining < 50 && data.has_food_in_inventory >= 0 && data.show_reset == false);
		var show_disabled = (data.health == 100 || data.food_remaining == 0);
		var valid_for_energy = data.food_remaining == 0 || data.has_food_in_inventory == 0;
		if(valid_for_energy && data.specialFoodAmount > 0) {
			hasSpecialItem = true;
			show_buy = false;
			show_warn = false;
			if(data.health < 100)
				show_disabled = false;
//			else show_disabled = true;
		} else hasSpecialItem = false;

		applyWarnStatus(show_warn);
		applyBuyStatus(show_buy);
		applySpecialFoodStatus(hasSpecialItem);
		applyDisableStatus(show_disabled);
		if(data.health < 100 && $j('#heal_btn').hasClass('health_kit_btn'))
			ERPK.enableHealButton();

	} catch(e) {;}
}

function applyDisableStatus(disable_status) {
	try {
		if(disable_status) {
			$j('#DailyConsumtionTrigger').removeClass('load');
			$j('#DailyConsumtionTrigger').addClass('disabled');
			$j('#heal_btn').addClass('disabled');
			//$j('#DailyConsumtionTrigger').unbind('click');
			//ERPK.disableHealButton();

		} else if($j('#DailyConsumtionTrigger').hasClass('disabled')) {
			$j('#DailyConsumtionTrigger').removeClass('disabled');
			$j('#heal_btn').removeClass('disabled');
		}
	} catch(e) {;}
}

function applyWarnStatus(warn_status) {
	try {
		if(warn_status) {
			if(!$j('#DailyConsumtionTrigger').hasClass('warn_on')) {
				$j('#DailyConsumtionTrigger').addClass('warn_on');
			}
		} else if($j('#DailyConsumtionTrigger').hasClass('warn_on')) {
			$j('#DailyConsumtionTrigger').remove('warn_on');
		}
	} catch(e) {;}
}

function applySpecialFoodStatus(special_food_status) {
	try {
		if(special_food_status) {
			if(!$j('#DailyConsumtionTrigger').hasClass('energy')) {
				addEnergy();
			}
		} else if($j('#DailyConsumtionTrigger').hasClass('energy') ||  $j('#heal_btn').hasClass('energy')) {
			removeEnergy();
		}
	} catch(e) {;}
}

function applyBuyStatus(buy_status) {
	try {
		if(buy_status) {
			$j('#DailyConsumtionTrigger').attr('href', linkForBuy);
			$j('#DailyConsumtionTrigger strong').html('Buy food');
			$j('#DailyConsumtionTrigger').addClass('buy');
			removeEnergy();
			if ($j('#heal_btn') != 'undefined'){
				if(!$j('#heal_btn').hasClass('health_kit_btn')){
					$j('#heal_btn').addClass('health_kit_btn')
					$j('#heal_btn').attr('title', 'Buy Food');
				}
				if(typeof(battleFX) != 'undefined') {
					$j('#health_warning').fadeOut();
					battleFX.noFoodWarning();
				}
			}
		}
	} catch(e) {alert(e);}
}

function applyEatStatus()
{
	$j('#DailyConsumtionTrigger').removeClass('buy');
	$j('#DailyConsumtionTrigger').removeClass('disabled');
	$j('#DailyConsumtionTrigger').removeClass('energy');
	$j('#DailyConsumtionTrigger').addClass('eat');
	$j('#DailyConsumtionTrigger strong').html('Eat');
	$j('#DailyConsumtionTrigger').attr('href', 'javascript:;');
}

function healthCounterResetCallback(hours, mins, secs) {
	if (hours == 0 && mins == 0 && secs == 0) {
		i = $j('#DailyConsumtionTrigger');
		$j(".resetFoodContainer").hide();
		$j("#foodText").show();
		i.removeClass('reset');
		//military client stuff
		if (typeof(battleFX) != 'undefined'){
			var h = $j('#heal_btn');
			h.removeClass('health_kit_btn');
			h.addClass('food_btn');
		}
		var val = parseFloat($j('#current_health').html());
		if (val < 100) {
			i.removeClass('disabled');
		}
		if (reset_has_food == 0 ) {
			i.removeClass('disabled');
			i.addClass('buy');
			$j("#foodText").html(textForBuy);
		}
		var t = food_remaining + 100;
		if(t >= reset_health_to_recover){
			food_remaining = reset_health_to_recover;
			$j("#foodResetHoursContainer").css('display', 'none');
		}else{
			food_remaining = t;
			var a = new ERPK.countDown({
				display   : $j("#foodResetHours"),
				startTime : "01:00:00",
				stopTime  : "00:00:00",
				onExpire  : healthCounterResetCallback
			});
			$j("#foodResetHoursContainer").css('display', 'block');
		}
		$j('.tooltip_health_limit').html(food_remaining +" / "+ reset_health_to_recover);
	}

}


function battleToggler(selector, timeout) {
    $j('.campaigns_header.'+selector).click(function(){
	if ($j('.holder_campaigns.'+selector).is(':visible')) {
	    $j('.campaigns_header.'+selector).addClass("toggled");
	    $j('.holder_campaigns.'+selector).slideUp(timeout, function(){
		$j('.holder_campaigns.'+selector).hide();
	    });
	}else {
	    $j('.campaigns_header.'+selector).removeClass("toggled");
	    $j('.holder_campaigns.'+selector).slideDown(timeout, function(){
		$j('.holder_campaigns.'+selector).show();
	    });
	}
    });

}

// Limit textarea chars
var onEditCallback = function(remaining){
    $j('#chars_remaining').text(remaining + " characters left");
    if(remaining > 0){
	$j(this).removeClass('maxchars');
    }
}

var onLimitCallback = function(){
    $j(this).addClass('maxchars');
}



try {
	HTMLElement.prototype.click = function() {
		var evt = this.ownerDocument.createEvent('MouseEvents');
		evt.initMouseEvent('click', true, true, this.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
		this.dispatchEvent(evt);
	}
}
catch(e){;}

