/*
======================================================================
 Liquid Nails: DIY Home page JavaScript.
======================================================================
*/

var DIYHome = Class.create();
DIYHome.prototype = {

	commId : 0,

	// Initializer.
	//
	initialize : function() {

		this.commId = new Date().getTime();

	}, // End initialize().

	// Load the home page Flash animation.
	//
	loadFlash : function() {

		var so = new SWFObject( '../flash/diy/DIYHome.swf', 'my_flashContentMovie', '800', '400', '8', '#ffffff' );

		so.addParam( 'wmode', 'transparent' );
		so.addParam( "scale", "noscale" );
		so.addParam( "salign", "lt" );

		so.addVariable( 'configXmlUrl', '../xml/diy/config.xml' );
		so.addVariable( 'resultsXmlUrl', '../xml/diy/results.xml' ); // This file really points to the results servlet.
		so.addVariable( 'showConsole', 'false' );
		so.addVariable( 'pathSavingEnabled', 'true' );
		so.addVariable( 'pathSavingCommId', this.getCommId() );
		so.addVariable( 'javaScriptEnabled', 'true' );
		so.addVariable( 'js_resizeFlashEvent', 'diyHome.resizeFlash' );
		so.addVariable( 'js_trackFlashEvent', 'diyHome.trackFlash' );
		so.addVariable( 'js_trackResultsFlashEvent', 'diyHome.trackResultsFlash' );

		so.write( 'my_flashContent' );

	}, // End loadFlash().

	// Resizes the height of the Flash plugin.
	resizeFlash : function( height ) {

		var obj = $( 'my_flashContentMovie' );
		obj.style.height = height + 'px';

	}, // End resizeFlash().

	// Tracks usage within the Flash plugin.
	//
	trackFlash : function( path ) {

		pageTracker._trackPageview( '/diy/selector' + path );

	}, // End trackFlash().
	
	// Tracks when the user reaches a results page within the Flash plugin.
	//
	trackResultsFlash : function( path ) {

		pageTracker._trackPageview( '/diy/selectorResultsReached' );

	}, // End trackResultsFlash().

	// Opens a product demo window.
	//
	openDemo : function( url ) {

		window.open( url, '',
			  'toolbar=no,location=no,status=no,menubar=no,'
			+ 'scrollbars=yes,resizable=yes,width=629,height=511' );

	}, // End openDemo().

	// Returns the path defined as an anchor in the URL.
	//
	getPath : function() {

		var path = '/';
		
		// Get the position of the URL's hash character.
		var anchorPos = window.location.href.indexOf( '#' ) + 1;
		if ( anchorPos > 0 ) {

			// Get the path from the URL anchor.
			path = window.location.href.substr( anchorPos );
		
			// Make sure the path starts with a slash.
			if ( path.startsWith( '/' ) == false ) path = '/' + path;

		} // End if.

		return path;

	}, // End getPath().

	// Returns the Flash Comm ID in use.
	//
	getCommId : function() {

		return this.commId;

	} // End getCommId().

} // End class DIYHome.

var diyHome = new DIYHome();
