/**
 * @author christopher
 */
var MenuTooltip = {
	totaltips: 0,
	
	tips: new Array(
		
		{
			"n": "music", 
			"s": new Array(
				[ "Music News", "Get the scoop on your favorite singers and groups.", "music.jpg" ],
				[ "Concerts", "Date, times, and ticket prices, along with venue information.", "concerts.jpg" ],
				[ "Listen", "Listen live to Q102 from anywhere in the world!", "listen.jpg" ]
			)
		},
		
		{
			"n": "games", 
			"s": new Array(
				[ "Contests", "Ways to win and official contest rules." ],
				[ "Games", "A selection of fun little games and time wasters to help you make it through the day." ],
				[ "Rewards", "Q102 Rewards - your shot at cool stuff just for being you!" ]
			)
		}
		
	),
	
	img_root: "/media/structure/menu/icons/",
	box: 0,
	box_offset_y: 30,
	box_offset_x: 30,
	
	init: function() {
		this.totaltips = this.tips.length;
		this.box = Element("div");
		this.box.className = "MenuTooltip_Box";
		getElement("menu").appendChild(this.box);
	},
	
	show: function(mid,icon) {
		for(var i=0;i<this.totaltips;i++) {
			if(this.tips[i].n == mid) {
				var title = FilledElement("h1",mid);
				var toc = Element("div");
				
				var c = Element("div");
				c.appendChild(title);
				c.appendChild(toc);
				
				var subitems = this.tips[i].s;
				for(var p=0;p<subitems.length;p++) {
					var s = FilledElement(
						"div",
						[
							FilledElement("img",this.img_root + subitems[p][2]),
							FilledElement("h2",subitems[p][0]),
							FilledElement("p",subitems[p][1])
						]
					);
					c.appendChild(s);
				}
				
				
				Clear(this.box);
				this.box.appendChild(c);
				
				icon = getElement(icon);
				
				
				var pos = this.getIconPosition(icon);
				
				this.box.style.top = (pos.y + this.box_offset_y) + "px";
				this.box.style.left = (pos.x + this.box_offset_x) + "px";
				
				show(this.box);
			}
		}
	},
	
	hide: function() {
		hide(this.box);
	},
	
	getIconPosition: function(obj) {
	    var topValue = 0, leftValue = 0;
	    while(obj){
			leftValue += obj.offsetLeft;
			topValue += obj.offsetTop;
			obj = obj.offsetParent;
	    }
		return { "x": leftValue, "y": topValue };
	}

}
