VIEWS.News = {
    
    menu: ['MenuMenu', 'AboutMenu', 'DistributionMenu', 'NewsMenu', 'ContactMenu'],
    menuPos: 2,
	
    init: function(args) {
        this.loadText();    
    },
    	
	updateTextPos: function(direction){
		var textStyle = $('NewsText').getStyle('top');
		var textHeight = $('NewsTextDiv').getHeight()  - $('NewsText').getHeight();
		var textStyle = (parseInt(textStyle.substring(0, textStyle.length - 2)) + (direction * 40));
		var safeSizeDown = ((textStyle)*(-1));
		
		if((safeSizeDown > textHeight) && (safeSizeDown + textHeight) > 0) {
			textStyle = (textHeight-20);
		} else if(textStyle > 0) {
			textStyle = 0;
		}
	
		if(textStyle > textHeight && ($('NewsTextDiv').getHeight() < $('NewsText').getHeight())) {
			$('newsTextDOWNOSD').show();
		} else {
			$('newsTextDOWNOSD').hide();
		}
		
		if(textStyle < 0 && ($('NewsTextDiv').getHeight() < $('NewsText').getHeight())){
			$('newsTextUPOSD').show();
		} else {
			$('newsTextUPOSD').hide();
		}
		
		if(direction < 0 && textStyle >= (textHeight-20)) {
			$('NewsText').setStyle({
				top: textStyle + "px"
			});		
		} else if(direction > 0 && textStyle <= 0){
			$('NewsText').setStyle({
				top: textStyle + "px"
			});
		}
	},
	
    show: function() {
        AMOSTV.showView('News');
		VIEWS.GoogleMenu.show(4);
		VIEWS.GoogleMenu.setFocus();
		AMOSTV.stopLoading();
		_gaq.push(['_trackPageview', '/amosgtv/news']);
    },
    
    exit: function() {
    },
    
    keyHandler: function(key) {
        if ( key == KEYS.BACK || key == KEYS.ESC ) {
			VIEWS.GoogleMenu.hide();
            AMOSTV.loadPreviousView();
        }
		
		if ( key == KEYS.RIGHT ) {
			VIEWS.GoogleMenu.keyHandler("right");
        }
		
		if ( key == KEYS.LEFT ) {
			VIEWS.GoogleMenu.keyHandler("left");
		}
		
		if ( key == KEYS.UP ) {
				this.updateTextPos(1);
		}
		
		if ( key == KEYS.DOWN ) {
				this.updateTextPos(-1);
		}
		if ( key == KEYS.OK ) {
			VIEWS.GoogleMenu.keyHandler("ok");
		}
    },
    
    loadText: function() {
		var self = this;
        /*new Ajax.Request("amostv_news/newsevents.xml", { method: 'get',
            onSuccess: function(response){
				var json = response.responseXML.documentElement;

				// Needed for IE8/9
				var output = (typeof json.textContent == "undefined") ? json.text : json.textContent;
				
				var content = "<p><strong>AMOS is constantly growing! To stay in touch with our newest videos and to see exclusive previews and content not available anywhere else, please visit our Facebook page.</strong>";
				content += "<a href=\"http:\/\/www.facebook.com\/pages\/Amos-TV\/247640325261540\" target=\"_blank\"><img src=\"img\/\/logos\/f_logo.png\"><\/a>";
				content += "</p>";
				content += output;
				$('NewsText').innerHTML = content;
				self.show();
            },
            onFailure: function() {
                AMOSTV.networkError('ajax');
            }
        });*/
		self.show();
		$('NewsText').setStyle({
			top: "0px"
		});
		jQuery("#NewsTextDiv").fadeTo(1000,1,function()
		{
			var jScrollPaneContainer = jQuery("#News .jScrollPaneContainer");
			if(jScrollPaneContainer.length == 0)
			{
				jQuery("#NewsText").jScrollPane({scrollbarWidth:8,dragMinHeight:30,dragMaxHeight:30});
				jQuery(".arrowup").mousedown(function()
				{
					jQuery(".jScrollPaneContainer").trigger("up.jscrollpane");
				});
				jQuery(".arrowdown").mousedown(function()
				{
					jQuery(".jScrollPaneContainer").trigger("down.jscrollpane");
				});
				jQuery(".arrowup").mouseup(function()
				{
					jQuery(".jScrollPaneContainer").trigger("release.jscrollpane");
				});
				jQuery(".arrowdown").mouseup(function()
				{
					jQuery(".jScrollPaneContainer").trigger("release.jscrollpane");
				});
			}
		});
    },
	
	mouseClicked: function(buttonClicked){
		if(buttonClicked.indexOf('Menu') != -1){
			if(buttonClicked.length > 4){
				VIEWS.GoogleMenu.keyHandler("ok");
			}
		} else if(buttonClicked.indexOf('OSD') != -1 && buttonClicked.indexOf('DOWN') != -1) {
			this.keyHandler(KEYS.DOWN);
		} else if(buttonClicked.indexOf('OSD') != -1 && buttonClicked.indexOf('UP') != -1) {
			this.keyHandler(KEYS.UP);
		}
		
	}, 
	
	mouseOver: function(buttonHovered){

		if(buttonHovered.indexOf('Menu') != -1){ // we hover bottom menu
			if(buttonHovered.length > 4){
				this.menuYPos = 1;
				//this.loadMenu();
				VIEWS.GoogleMenu.focusElement(buttonHovered);
			}
		}
	}
}

