function Menu(){

	this.init.apply(this, arguments);
}
Menu.prototype.init = function(rootPath, selectedMenuId){

	var imgName;
	if(selectedMenuId == 0){
		var arr = String(document.location).split("?");

		// Now On Sale
		if(arr.length > 1 && arr[1] == "top")
			imgName = "1_2";
	}
	if(!imgName)
		imgName = selectedMenuId;

	var bgimgUri = [
		rootPath, "img/menu/", imgName, ".png"
	].join("");

	$("#menu li").each(function(id){

		new MenuItem(rootPath, bgimgUri, id + 1, this);
	});

	/*
	$("#menu").css({
		"background-image": "url('" + bgimgUri + "')",
		"background-repeat": "no-repeat",
		"background-position": "0px -" + (0) + "px"
	});
	*/
};

function MenuItem(){

	this.init.apply(this, arguments);
}
MenuItem.prototype.init = function(
	rootPath, bgimgUri, menuId, element){

	this.IMG_HEIGHT = 35;
	this.bgimgUri = bgimgUri;
	this.menuId = menuId;

	var menuName = 
		(menuId == 1) ? "" :
		(menuId == 2) ? "update" :
		(menuId == 3) ? "comics" :
		(menuId == 4) ? "serial" :
		(menuId == 5) ? "column" :
		(menuId == 6) ? "artist" :
		(menuId == 7) ? "competition" : "assistant";

	var linkUri = rootPath + menuName;
	if(menuId > 1) linkUri += "/";

	var sc = this;
	$(element).mouseover(function(){

		sc.viewBackgroundImage(sc.menuId);
	});
	$(element).mouseout(function(){

		sc.viewBackgroundImage(0);
	});

	$(element).click(function(){

		document.location.href = linkUri;
	});

	$(element).hover(
		function(){
			$(this).css('cursor', 'pointer');
		},
		function(){
			$(this).css('cursor', 'default');
		}
	);

	/*
	if(menuId == 1)
		this.viewBackgroundImage(0);
	*/
};
MenuItem.prototype.viewBackgroundImage = function(listId){

	$("#menu").css({
		"background-image": "url('" + this.bgimgUri + "')",
		"background-repeat": "no-repeat",
		"background-position": "0px -" + (this.IMG_HEIGHT * listId) + "px"
	});
};


