PaintingMenu = {
	element: "",
	menu: "show_painting",
	menuWidth: 164,
	startLeft: 11,
	startTop: 4,
	left: 0,
	top: 0,
	painting: new Image(),
	maxImageSize: 133,
	id: 0,
	info: "",
	cellPos: 1,
	rowPos: 1,
	moveWidth: 1,
	timeout: "",
	_show_extra: false,
	
	initFavoriteList: function(){
		this.setMenu("favorite_show_painting",15,33,59,146,100);
	},
	initSearchList: function(){
		var moveWidth = parseInt(document.getElementById("rowsWidth").value)+10;
		this.setMenu("show_painting",0,21,moveWidth,164,133);
	},
	initPainterList: function(){
		this.setMenu("show_painting",10,35,100,164,133);
	},
	
	setMenu: function(menuID,topPos,leftPos,moveWidth,width,imageWidth){
		this.hideMenu();
		this.menu = menuID;
		this.startTop = topPos;
		this.startLeft = leftPos;
		this.moveWidth = moveWidth;
		this.menuWidth = width;
		this.maxImageSize = imageWidth;
	},
	
	showMenu: function(info,cell,row){
		this.hideMenu();
		
		this._show_extra = false;
		if(document.getElementById("painting_id_"+info)){
			this.element = document.getElementById("painting_id_"+info);
			var elm = this.element.elements;
			this.painting.src = elm["filnavn"].value;
			this.id = elm["id"].value;
			this.info = new Array(elm["titel"].value,elm["dimension"].value,elm["pris"].value);
			this._show_extra = (elm["profil"].value != "");
		}
		else{
			this.painting.src = info["filnavn"];
			this.id = info["id"];
			this.info = new Array(info["titel"],info["dimension"],info["pris"]);
		}
		this.cellPos = cell;
		this.rowPos = row;
		
		var w = this.moveWidth-10;
		this.left = this.startLeft - Math.round((this.menuWidth-w)/2);
		this.top = this.startTop;
		
		this.mark();
		this.paint();
	},
	
	hideMenu: function(){
		this.hide();
	},
	
	mark: function(){

	},
	
	unmark: function(){

	},
	
	paint: function(){
		var execute = function(){
			elm = document.getElementById(PaintingMenu.menu);
			img = document.getElementById(PaintingMenu.menu+"_img");
			info = document.getElementById(PaintingMenu.menu+"_info");
			var echoSize = "";
			
			elm.style.left = (PaintingMenu.cellPos*PaintingMenu.moveWidth+PaintingMenu.left)+"px";
			elm.style.top = (PaintingMenu.rowPos*PaintingMenu.moveWidth+PaintingMenu.top)+"px";
			
			(PaintingMenu.painting.height > PaintingMenu.painting.width) ? echoSize = "height='"+PaintingMenu.maxImageSize+"'" : echoSize = "width='"+PaintingMenu.maxImageSize+"'";
			
			img.innerHTML = "<img src='"+PaintingMenu.painting.src+"' alt='image' "+echoSize+" />";
			
			info.innerHTML = PaintingMenu.info[2]+"kr"+"<br />"+PaintingMenu.info[1]+"cm<br />"+PaintingMenu.info[0];
			
			if(PaintingMenu._show_extra){
				document.getElementById("show_painting_extra").innerHTML = "Henter...";
				YAHOO.util.Connect.asyncGetRequest("includes/painting_menu_extra.php?id="+PaintingMenu.id,"show_painting_extra","");
				document.getElementById("show_painting_extra").style.display = "block";
				
			}
			else
				document.getElementById("show_painting_extra").style.display = "none";
				
			document.getElementById(PaintingMenu.menu).style.display = "block";
			PaintingMenu.unmark()
		}

		
		this.cancel();
		this.timeout = setTimeout(execute,300);
	},
	
	hide: function(){
		elm = document.getElementById(this.menu);
		if(elm)
			elm.style.display = "none";
	},
	
	cancel: function(){
		clearTimeout(this.timeout);
	},
	
	favoritAddLink: function(){
		List.add(this.id,this.painting.src);
	},
	
	favoritDelLink: function(){
		List.remove(this.id);
	},
	
	buyLink: function(fragt,paintingId){
		var query = '../kurv/kurv.php?kob=true&ajax=true&id=';
		if(paintingId)
			query += paintingId;
		else
			query += this.id;
		if(fragt)
			query += "&fragt="+fragt;

		YAHOO.util.Connect.asyncGetRequest(query,'kurvHTML','',function(){DialogBox.paintAddBasketBox()});
	},
	
	viewLink: function(){
		PaintingView.paint("maleri",this.id);
	}
}
