//  StoryViewAssistant(storyFeed, storyIndex)
//
//  Passed a story element, displays that element in a full scene view and offers options
//  for next story (right command menu button), previous story (left command menu button)
//  and to launch story URL in the browser (view menu).
function StoryViewAssistant(storyFeed, storyIndex) {
	//    Save the passed arguments for use in the scene.
    //
	this.storyFeed = storyFeed;
    this.storyIndex = storyIndex;
}

StoryViewAssistant.prototype.setup = function() {
    // Hide Previous Button if first story, and Next Button if last one
    if (this.storyIndex > 0)   {
    	this.controller.listen('previousStory', Mojo.Event.tap, this.previousStory.bindAsEventListener(this));
    } 
	else {
        $('previousStory').hide();
    }
	
    if (this.storyIndex < this.storyFeed.stories.length-1)  {
    	this.controller.listen('nextStory', Mojo.Event.tap, this.nextStory.bindAsEventListener(this));
    } else  {
    	$('nextStory').hide();
    }
	
	this.controller.listen('backToFeed', Mojo.Event.tap, this.goBack.bindAsEventListener(this));
};

StoryViewAssistant.prototype.goBack = function(event) {
	Mojo.Controller.stageController.popScene();
};


StoryViewAssistant.prototype.previousStory = function(event) {
    //Mojo.Controller.stageController.pushScene("storyView", this.storyFeed, this.storyIndex-1);
	Mojo.Controller.stageController.swapScene("storyView", this.storyFeed, this.storyIndex-1);
};

StoryViewAssistant.prototype.nextStory = function(event) {
    //Mojo.Controller.stageController.pushScene("storyView", this.storyFeed, this.storyIndex+1);	
	Mojo.Controller.stageController.swapScene("storyView", this.storyFeed, this.storyIndex+1);	
};

StoryViewAssistant.prototype.activate = function(event) {
    $("storyViewTitle").innerHTML = this.storyFeed.stories[this.storyIndex].title;
    $("storyViewSummary").innerHTML = this.storyFeed.stories[this.storyIndex].text;
	
	if (this.storyFeed.stories[this.storyIndex].unReadStyle === unReadFormatting)   {
        this.storyFeed.numUnRead--;
        this.storyFeed.stories[this.storyIndex].unReadStyle = "";
    }
};

StoryViewAssistant.prototype.deactivate = function(event) {
};

StoryViewAssistant.prototype.cleanup = function(event) {
};