
// Main screen turn on. It's You! Hello gentlemen how are you?
VIEWS.Menu = {
    
   // buttons: [ 'about', 'move', 'enter', 'return' ],
    
    menu: ['', 'rise', 'rally', 'rest', 'rebel'],
    menuPos: 1,
	menuYPos: 0,
	menuAmos: 'rise',
    
    init: function(args) {
		this.googleHighlight = 'MenuMenu';
		this.menuPos = 1;
        this.loadMenu();
        AMOSTV.stopLoading();
        AMOSTV.showView('Menu');
		VIEWS.GoogleMenu.show(0);
		window.name = 'amostv_notrailer';
		_gaq.push(['_trackPageview', '/amosgtv/mainMenu']);
    },
    
    exit: function() {
        
    },
    
    loadMenu: function() {
        // deactivate all
		for ( var i = 1; i < this.menu.length; i++ ) {
				$(this.menu[i] + '_desc').hide();
				$(this.menu[i] + '_menu').className = '';
		}
		
        // activate selected
		if(this.menuYPos == 0){
			$(this.menu[this.menuPos] + '_desc').show();
			$(this.menu[this.menuPos] + '_menu').className = 'hilited';
		}
    },
    
    keyHandler: function(key) {
        if ( key == KEYS.OK ) {
			if(this.menuYPos == 0){
				AMOSTV.loadView('List', {player: this.menu[this.menuPos]});
			} else {
				VIEWS.GoogleMenu.keyHandler("ok");
			}
        }
        if ( key == KEYS.LEFT ) {
			if(this.menuYPos == 0){
				//different player is focused
				if ( this.menuPos > 1 ) {
					this.menuPos--;
					this.menuAmos = this.menu[this.menuPos];
					this.loadMenu();
				}
			} else { // if bottom menu is focused
				VIEWS.GoogleMenu.keyHandler("left");
			}
        }
        if ( key == KEYS.RIGHT ) {
			if(this.menuYPos == 0){
				if ( this.menuPos < 4 ) {
					this.menuPos++;
					this.menuAmos = this.menu[this.menuPos];
					this.loadMenu();
				}
			} else { // if bottom menu is focused
				VIEWS.GoogleMenu.keyHandler("right");
			}
        }
		
		if ( key == KEYS.UP ) {
			if(this.menuYPos == 1){
				this.menuYPos = 0;
				switch(VIEWS.GoogleMenu.menuPos) {
					case 0: this.menuPos = 1; break;
					case 1: this.menuPos = 2; break;
					case 2: this.menuPos = 2; break;
					case 3: this.menuPos = 3; break;
					case 4: this.menuPos = 4; break;
					default: this.menuPos = this.menu.indexOf(this.menuAmos); break;
				}
				VIEWS.GoogleMenu.looseFocus();
				this.loadMenu();
			}
		}
		
		if ( key == KEYS.DOWN ) {
			if(this.menuYPos == 0){
				this.menuYPos = 1;
				switch(this.menuPos) {
					case 1: VIEWS.GoogleMenu.menuPos = 0; break;
					case 2: VIEWS.GoogleMenu.menuPos = 1; break;
					case 3: VIEWS.GoogleMenu.menuPos = 3; break;
					case 4: VIEWS.GoogleMenu.menuPos = 4; break;
					default: VIEWS.GoogleMenu.menuPos = 0; break;
				}
				VIEWS.GoogleMenu.setFocus();
				this.loadMenu();
			}
		}
		
        if ( key == KEYS.BACK ) {
        }
    },
	
	mouseClicked: function(buttonClicked){
		if(buttonClicked.indexOf('_menu') != -1){
			AMOSTV.loadView('List', {player: this.menu[this.menuPos]});
		} else if(buttonClicked.indexOf('Menu') != -1){
			if(buttonClicked.length > 4){
				VIEWS.GoogleMenu.keyHandler("ok");
			}
		}
		
	}, 
	
	mouseOver: function(buttonHovered){

		if(buttonHovered.indexOf('_menu') != -1){ // we hover a playlist category
			this.menuPos = this.menu.indexOf(buttonHovered.substring(0,buttonHovered.length-5));
			this.menuYPos = 0;
			VIEWS.GoogleMenu.looseFocus();
			this.loadMenu();
		} else if(buttonHovered.indexOf('Menu') != -1){ // we hover bottom menu
			if(buttonHovered.length > 4){
				this.menuYPos = 1;
				this.loadMenu();
				VIEWS.GoogleMenu.focusElement(buttonHovered);
			}
		}
	}
};
jQuery(window).load(function()
{
	jQuery("#rise_menu,#rally_menu,#rest_menu,#rebel_menu").hover(function(){VIEWS.Menu.mouseOver(this.id);},function(){});
	jQuery("#rise_menu,#rally_menu,#rest_menu,#rebel_menu").click(function(){VIEWS.Menu.mouseClicked(this.id);});
	var panelw = 0;
	jQuery(".panel .item").each(function()
	{
		panelw += jQuery(this).outerWidth(true);
	});
	jQuery(".panel").width(panelw);
	jQuery(".panel .item img").hover(
	function()
	{
		jQuery(this).animate({left:'-=10',bottom:'-=10',width:'+=20',zIndex:3},400);
		var parent_item = jQuery(this).parent().parent();
		jQuery(".text",parent_item).css({color:'#3f7c22'});
		jQuery(".text",parent_item).animate({bottom:'-=10'},400);
	}
	,
	function()
	{
		jQuery(this).animate({left:'+=10',bottom:'+=10',width:'-=20',zIndex:"inherit"},400);
		var parent_item = jQuery(this).parent().parent();
		jQuery(".text",parent_item).css({color:'#F56C0B'});
		jQuery(".text",parent_item).animate({bottom:'+=10'},400);
	}
	);
	jQuery(".makeleft").hover(function()
	{
		jQuery(".panel").animate({left:0},1000);
	},
	function()
	{
		jQuery(".panel").stop();
	});
	jQuery(".makeright").hover(function()
	{
		var scw = jQuery(".scrollme").width();
		var pw  = jQuery(".panel").width();
		var nl = 0;
		if(pw >= (scw))
		{
			nl = (pw*-1)+(scw);
		}
		jQuery(".panel").animate({left:nl},1000);
	},
	function()
	{
		jQuery(".panel").stop();
	});
});
