
// The Top Ten Page class.
var TopTenPage = Class.create();

TopTenPage.prototype =
{
	initialize : function()
	{
	},
	
	getQueryParameter : function(paramName)
	{ 
		var query = window.location.search.substring(1); 
		var vars  = query.split("&"); 

		for (var i = 0; i < vars.length; i++)
		{ 
			var pair = vars[i].split("="); 
			if (pair[0] == paramName)
			{
				return pair[1]; 
			} 
		}
	},
	
	loadFlash : function()
	{	
		var flashvars =
		{
				xmlStreamPath  : '../color/get-color-xml.do?type=color-visualizer',
				targetTop10Id  : this.getQueryParameter('id' ),
				targetTop10Sku : this.getQueryParameter('sku')
		};
	
		var params =
		{
			base            : '',
			menu            : 'false',
			wmode           : 'transparent',
			bgcolor         : '#ffffff',
			allowFullScreen : 'true'
		};
	
		swfobject.embedSWF('../flash/inspiration/top-10-color-palettes/top10.r16.swf', 'my_flashContent', '940', '722', '9.0.0', null, flashvars, params, null);	
	},
	
	sharePage : function()
	{	
		shareDialog.show( this.getBaseUrl(), 'Top 10 Colors', 'Share This Tool' );
	},

	// Returns the base URL without session or query information.
	//
	getBaseUrl : function()
	{	
		var retVal = window.location.href;
	
		// Remove the anchor information.
		var anchorPos = retVal.indexOf( '#' );
		if ( anchorPos > 0 ) {
	
			var retVal = window.location.href.substr( 0, anchorPos );
	
		} // End if.

		// Remove the session ID information.
		var sessionIdPos = retVal.indexOf( ';' );
		if ( sessionIdPos > 0 ) {
	
			var retVal = window.location.href.substr( 0, sessionIdPos );
	
		} // End if.
	
		// Remove the query variables.
		var queryPos = retVal.indexOf( '?' );
		if ( queryPos > 0 ) {
	
			var retVal = window.location.href.substr( 0, queryPos );
	
		} // End if.
	
		return retVal;	
	}

}

var topTenPage = new TopTenPage();

//----- Functions called from the Flash component
function sharePage()
{
	topTenPage.sharePage();
}
