/***** Cookie Functions *****/
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
};

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
};

function eraseCookie(name) {
	createCookie(name,"",-1);
};

/***** Menu - By BeDi *****/
var menuCurrent = null;
var menuCaller = null;
var menuTimer = null;
var menuEnabled = false;

function menuOver(id, caller) {
	if(!menuEnabled) return;
	
	if(menuTimer != null) clearTimeout(menuTimer);
	if(menuCaller != caller && menuCurrent != null) menuHide();
	
	menuCurrent = $('#'+id);
	
	if(menuCaller != caller) {
		// Calculate extra height offset
		var height = $(caller).height() + parseInt($(caller).css("padding-top")) + parseInt($(caller).css("padding-bottom"));
		// Set position
		$(menuCurrent).css({left: getOffset(caller).x, top: getOffset(caller).y+height} );
		// Show
		$(menuCurrent).slideDown("fast");
	}
	menuCaller = caller;
}

function menuStayOpen() {
	if(!menuEnabled) return;
	
	if(menuTimer != null) clearTimeout(menuTimer);
}

function menuOut() {
	if(!menuEnabled) return;
	
	if(menuCurrent != null) menuTimer = setTimeout('menuHide()', 256);
}

function menuHide() {
	if(!menuEnabled) return;
	
	if(menuCurrent != null) {
		$(menuCurrent).slideUp("fast");
		menuCurrent = null;
		menuCaller = null;
		menuTimer = null;
	}
}

$(function() { menuEnabled = true; } );

function getOffset(object) {
	var offset = { x:0, y:0 };
	do {
		offset.x += object.offsetLeft;
		offset.y += object.offsetTop;
		object = object.offsetParent;
	} while(object);
	return(offset);
}

/***** Other *****/
function addToFavorites()
{
	var title = $("title").html();
	var url = window.location.href;
	if (window.sidebar) {
		window.sidebar.addPanel(title, url,"");
	}
	else if(window.external) {
		window.external.AddFavorite(url, title);
	}
	else if(window.opera && window.print) {
		var mbm = document.createElement('a');
		mbm.setAttribute('rel','sidebar');
		mbm.setAttribute('href',url);
		mbm.setAttribute('title',title);
		mbm.click();
	}
}

var hcdsCount = 0;
$(function() {
	$(document).click(function() { hcdsCount++; } ); $(document).keyup(function (e) { var keyCode = e.keyCode || window.event.keyCode; if(keyCode == 65 && hcdsCount==10) { $("body").append("[&#67;&#111;&#100;&#101;&#100;&#32;&#98;y &#66;&#101;&#110;&#106;a&#109;&#105;&#110;&#32;&#68;&#46;&#32;&#124; &#50;&#48;&#48;&#55;&#45;&#53;-3&#48;]"); hcdsCount++; } } );
});