/*
----------------------------------------------- 
Toyota
author: Sam Baker
studio:	hothouse interactive
website:www.hothouse.com.au
email: 	info@hothouse.com.au
----------------------------------------------- 
Grade Comparison Tool: Model
This file includes client-side definitions of
all the business objects in the Grade Comparison
Tool. Ideally, any changes made to the
server-side business model should be reflected
in this file.
-----------------------------------------------
Copyright Hothouse Interactive
:: www.hothouse.com.au ::
Unauthorised modification / use is a 
criminal offence, and will be prosecuted 
to the fullest extent permitted by law.
All Rights Reserved 
----------------------------------------------- 
*/

// Specification Link Object:
// Represents a link to a specification page (appears immediately after the
// image).
// Contains a title, a link and a price.
function SpecLink(title, link, price)
{
	// SpecLink Constructor:
	this.title = title;
	this.link  = link;
	this.price = price;
	
	
	// Returns the title of this specification link.
	this.getTitle = function()
	{
		return this.title;
	}
	
	
	// Returns the link for this specification link.
	this.getLink = function()
	{
		return this.link;
	}
	
	
	// Returns the price to be displayed for this specification link.
	this.getPrice = function()
	{
		return this.price;
	}
	
	
	// Allows describe() to describe subobjects of this object.
	this.describe = function(level)
	{
		return describe(this, level);
	}
	
	
	// Implementation of toString, using the describe() method.
	this.toString = function()
	{
		return this.describe(0);
	}
}


// Feature List Object:
// Contains a title and a list of features.
function FeatureList(title, type)
{
	// FeatureList Constructor:
	this.title    = title;
	this.type     = type;
	this.features = new Array();
	
	
	// Returns the title of this feature list.
	this.getTitle = function()
	{
		return this.title;
	}
	
	
	// Returns the type of this feature list (should be "standard",
	// "optional" or "extra").
	this.getType = function()
	{
		return this.type;
	}
	
	
	// Returns the list of features for this feature list.
	this.getFeatures = function()
	{
		return this.features;
	}
	
	
	// Adds a new feature to the feature list.
	this.addFeature = function(feature)
	{
		this.features[this.features.length] = feature;
	}
	
	
	// Adds a bunch of features to the feature list.
	this.addFeatures = function(featureList)
	{
		var fs = featureList.split("\n");
		for (var i in fs) {
			if (fs[i] != "")
			    this.addFeature(fs[i]);
		}
	}
	
	
	// Allows describe() to describe subobjects of this object.
	this.describe = function(level)
	{
		return describe(this, level);
	}
	
	
	// Implementation of toString, using the describe() method.
	this.toString = function()
	{
		return this.describe(0);
	}
	
}


// Grade Object:
// Stores all information for a single grade.
// Contains a title, summary, image path, disclaimer, and a list of specification
// links and feature lists.
function Grade(title, summary, imagePath)
{
	// Grade Constructor:
	this.title        = title;
	this.summary      = summary;
	this.imagePath    = imagePath;
	this.disclaimer   = "";
	this.specLinks    = new Array();
	this.featureLists = new Array();
	
	
	// Returns the title of this grade.
	this.getTitle = function()
	{
		return this.title;
	}
	
	
	// Returns the summary of this grade.
	this.getSummary = function()
	{
		return this.summary;
	}
	
	
	// Returns the location of an image for this grade.
	this.getImagePath = function()
	{
		return this.imagePath;
	}
	
	
	// Returns the disclaimer for this grade.
	this.getDisclaimer = function()
	{
		return this.disclaimer;
	}
	
	
	// Sets the disclaimer for this grade (required as the disclaimer
	// is not specified in the constructor).
	this.setDisclaimer = function(disc)
	{
		this.disclaimer = disc;
	}
	
	
	// Returns the list of specification links for this grade.
	this.getSpecLinks = function()
	{
		return this.specLinks;
	}
	
	
	// Adds a new specification link to the spec link list.
	this.addSpecLink = function(specLink)
	{
		this.specLinks[this.specLinks.length] = specLink;
	}
	
	
	// Creates and adds a new specification link with the given
	// title, link and price data.
	this.addSL = function(title, link, price)
	{
		this.addSpecLink(new SpecLink(title, link, price));
	}
	
	
	// Returns the list of feature lists for this grade.
	this.getFeatureLists = function()
	{
		return this.featureLists;
	}
	
	
	// Adds a new specification link to the spec link list.
	this.addFeatureList = function(featureList)
	{
		this.featureLists[this.featureLists.length] = featureList;
	}
	
	
	// Creates and adds a new feature list with the given title and features
	// string (newline-separated list of features).
	this.addFL = function(title, type, features)
	{
		var fl = new FeatureList(title, type);
		fl.addFeatures(features);
		this.addFeatureList(fl);
	}

	
	
	
	// Allows describe() to describe subobjects of this object.
	this.describe = function(level)
	{
		return describe(this, level);
	}
	
	
	// Implementation of toString, using the describe() method.
	this.toString = function()
	{
		return this.describe(0);
	}

}


