VIEWS.GoogleMenu = {
	menuPos: 0,
	menu: ['MenuMenu', 'AboutMenu', 'StreamMenu' , 'DistributionMenu', 'NewsMenu', 'ContactMenu'],
	pageShown: "",
	
	init: function(){
		
	},
	
	hide: function(){
		$(this.pageShown + "Menu").className = '';
		$('GoogleMenu').hide();
	},
	
	show: function(menuPos){
		this.looseFocus();
		this.menuPos = menuPos;
		$('GoogleMenu').show();
		$(this.menu[this.menuPos]).className = 'hilited';
		this.pageShown = this.menu[this.menuPos].substring(0, this.menu[this.menuPos].length-4); // remove the ending Menu of string
		//this.setFocus();
	},
	
	removeHilight: function(){
	
	},
	
	/*unfocusMenuPos: function(prevPos){
	
	},
	
	focusMenuPos: function(previewPos) {
		if(prevPos != 'null')
			$(prevPos).removeClassName("focused");
			
		this.menuPos = previewPos;
		$(this.menuPos).addClassName("focused");
	},*/
	
	// function to set focus on the current selected button
	setFocus: function(){
		$(this.menu[this.menuPos]).addClassName("hilited");
	},
	
	// function to remove focus
	looseFocus: function() {
		if(this.menuPos >= 0 && this.menuPos <= this.menu.length - 1)
		{
			$(this.menu[this.menuPos]).removeClassName("hilited");
		}
		jQuery(".facebook img").attr("src","img/buttons/fb.png");
		jQuery(".youtube img").attr("src","img/buttons/yt.png");
		jQuery(".twitter img").attr("src","img/buttons/twitter.png");
		
	},
	
	keyHandler: function(action){
		switch(action){
			case "left":
				if(this.menuPos > 0 && this.menuPos <= this.menu.length + 2)
				{
					this.looseFocus();
					this.menuPos--;
					if(this.menuPos >= 0 && this.menuPos <= this.menu.length - 1)
					{
						this.setFocus();
					}
					else
					{
						if(this.menuPos >= 0)
						{
							if(this.menuPos == this.menu.length)
							{
								jQuery(".facebook img").attr("src","img/buttons/fb_roll.png");
							}
							if(this.menuPos == this.menu.length+1)
							{
								jQuery(".youtube img").attr("src","img/buttons/yt_roll.png");
							}
							if(this.menuPos == this.menu.length+2)
							{
								jQuery(".twitter img").attr("src","img/buttons/twitter_roll.png");
							}
						}
					}
				}
			break;
			
			case "right":
				if(this.menuPos <= this.menu.length + 1)
				{
					this.looseFocus();
					this.menuPos++;
					if(this.menuPos <= this.menu.length - 1)
					{
						this.setFocus();
					}
					else
					{
						if(this.menuPos == this.menu.length)
						{
							jQuery(".facebook img").attr("src","img/buttons/fb_roll.png");
						}
						if(this.menuPos == this.menu.length+1)
						{
							jQuery(".youtube img").attr("src","img/buttons/yt_roll.png");
						}
						if(this.menuPos == this.menu.length+2)
						{
							jQuery(".twitter img").attr("src","img/buttons/twitter_roll.png");
						}
					}
				}
			break;
			
			case "ok":
				if(this.menuPos >= 0 && this.menuPos <= this.menu.length - 1)
				{
					//substract last Menu to get a correct name for the view
					var selectedMenu = this.menu[this.menuPos].substring(0, this.menu[this.menuPos].length-4); 
					if(this.pageShown != selectedMenu)
					{
						this.hide();
						AMOSTV.loadView(selectedMenu);
						window.location = jQuery("#"+this.menu[this.menuPos]).attr("href");
					}
				}
				else
				{
					if(this.menuPos >= 0)
					{
						if(this.menuPos == this.menu.length)
						{
							window.location = jQuery(".facebook a").attr("href");
						}
						if(this.menuPos == this.menu.length+1)
						{
							window.location = jQuery(".youtube a").attr("href");
						}
						if(this.menuPos == this.menu.length+2)
						{
							window.location = jQuery(".twitter a").attr("href");
						}
					}
				}
			break;
		}
	},
	
	//function to set focus on a menuitem with name
	focusElement: function(menuName){
		this.looseFocus();
		this.menuPos = this.menu.indexOf(menuName);
		this.setFocus();
	}, 
	
	mouseClicked: function(buttonClicked){
		if(buttonClicked.indexOf('Menu') != -1){
			if(buttonClicked.length > 4){
				var selectedMenu = this.menu[this.menuPos].substring(0, this.menu[this.menuPos].length-4);
				if(this.pageShown != selectedMenu){
					//if(selectedMenu === "Menu" || selectedMenu === "About"  || selectedMenu === "Distribution" ){
						this.hide();
						AMOSTV.loadView(selectedMenu);
					//}
				}
			}
		}
	}, 
	
	mouseOver: function(buttonHovered){	
		if(buttonHovered.indexOf('Menu') != -1){
			if(buttonHovered.length > 4){
				//this.menuYPos = 1;
				//this.loadMenu();
				//VIEWS.GoogleMenu.focusElement(buttonHovered);
				this.focusElement(buttonHovered);
			}
		}
	}
}
