/**
 * Rock the Space 2
 *
 * Description: 
 * 1) Behaviors: Share Tracking and Embed Code Copy Button
 * 2) sIFR
 * 3) Eliminate hover flicker in IE6
 *
 * @requires swfobject
 *
*/

/** 
 * Instantiate Gigya Reporting object
 */
swfobject.registerObject("GigyaReporting", "9.0.115");


// Global Namespace
var RTS2 = window.RTS2 || {};

/**
 * Behaviors
 * Track share link and copy actions. Activate embed code copy button.
 * @returns init - Initializes these behaviors
 *
 * @requires GigyaReporting.swf, ZeroClipboard.min.js, ZeroClipboard.swf
 */
RTS2.Behaviors = (function () {
	var pub = { }; // Stores public items returned

	/** 
	 * initShare (private)
	 * Applies behavior to share links
	 *
	 * @requires reportEvent
	 */
	function initShare() {
		var share = document.getElementById('share'),
			shareLinks = share.getElementsByTagName('a');
		
		for (var i = 0; i < shareLinks.length; i++) {
			shareLinks[i].onclick = reportEvent;
		}
	}
	
	/** 
	 * reportEvent (private)
	 * Reports activation of a share link or the copy button
	 *
	 * @see initShare
	 * @see initCopyCode
	 */	
	function reportEvent(eventName) {
		/* @TODO Replace cid with the proper value:
			Development is 1223261
			Production is 1167191
		*/
		var cid="1167191";		
					
		if (eventName !== 'install:embed') {
			var shareSite = (this.childNodes[0].nodeValue).toLowerCase();
			eventName = 'install:' + shareSite + '';
		}
			
		swfobject.getObjectById("GigyaReporting").reportEvent(eventName, cid);
	}
	
	/** 
	 * initCopyCode (private)
	 * Initializes embed code copy button
	 *
	 * @requires reportEvent
	 */
	function initCopyCode() {
		if (swfobject.hasFlashPlayerVersion("9.0.0")) {
		
			// show Copy button
			document.getElementById('btnContainer').style.display = 'block';
		
			/* @NOTE Change setMoviePath to your location of the SWF. 
				Or, if you put the SWF in the same directory as the HTML page, 
				you don't need to declare setMoviePath at all. */
			ZeroClipboard.setMoviePath('http://stage-creative.myspacecdn.com/Client/Toyota/RockTheSpace/cmn/swf/ZeroClipboard.swf');
			var clip = new ZeroClipboard.Client();
			
			 // the code that is copied
			clip.setText((''+ document.getElementById('embedCode').value +''));
		
			// attach copy behavior
			clip.glue('btnCopy', 'btnContainer');
		
			// report tracking of embed copy
			clip.addEventListener('onComplete', function() {
					return reportEvent('install:embed');
				}
			);
		}
	}

	/** 
	 * init (public)
	 * Initialize behaviors
	 *
	 * @requires initShare
	 * @requires initCopyCode
	 */	
	pub.init = function () {
		initShare();
		initCopyCode();
	};
	
	return pub;
}()); // end RTS2.Behaviors


/**
 * Eliminate hover flicker in IE6
 */
try {
	document.execCommand("BackgroundImageCache", false, true);
} catch(e) {}


/**
 * Applies sIFR to specified text
 *
 * @requires sifr.js
 */
(function (sIFR) {
	if (sIFR) {
		var futura_bold = {
			src: 'http://stage-creative.myspacecdn.com/Client/Toyota/RockTheSpace/cmn/swf/futura-bold.swf', /* @NOTE Set path to SWF if moved */
			ratios: [6, 1.49, 8, 1.5, 9, 1.44, 12, 1.45, 17, 1.42, 20, 1.41, 23, 1.4, 26, 1.39, 27, 1.37, 30, 1.38, 32, 1.37, 35, 1.38, 42, 1.37, 44, 1.36, 47, 1.37, 60, 1.36, 62, 1.35, 63, 1.36, 65, 1.35, 66, 1.36, 108, 1.35, 110, 1.34, 111, 1.35, 113, 1.34, 114, 1.35, 116, 1.34, 117, 1.35, 119, 1.34, 121, 1.35, 122, 1.34, 124, 1.35, 1.34]
		};
		
		sIFR.activate(futura_bold);
		
		sIFR.useStyleCheck = true;
		
		// Band Name.
		sIFR.replace(
			futura_bold,
			{
				selector: '#header h2',
				css: [
					'.sIFR-root { background-color: #000000; color: #ffffff; }'
				],
				wmode: 'opaque',				
				offsetTop: -3,
				offsetLeft: -1,
				tuneHeight: -10
			}
		);
		
		// Band MySpace Profile URL.
		sIFR.replace(
			futura_bold,
			{
				selector: '#header h3',
				css: [
					'.sIFR-root { background-color: #000000; }',
					'a { text-decoration: none; }',
					'a:link { color: #15b2b7; }',
					'a:hover { color: #ffffff; }'
				],
				wmode: 'opaque',
				offsetTop: -3,
				tuneHeight: -10
			}
		);
		
		// Stats.
		sIFR.replace(
			futura_bold,
			{
				selector: '#stats li',
				css: [
					'.sIFR-root { color: #1a1a1a; }',
					'h4 { color: #fefefe; font-size: 65.466448445171849427168576104746%; }'
				],
				filters: {
					DropShadow: {
						distance: 1,
						color: '#1a1a1a',
						strength: 1,
						alpha: .1,
						angle: 90
					}
				},
				wmode: 'transparent',
				offsetTop: -9,
				offsetLeft: -2,
				tuneHeight: -21
			}
		);
	}
}(window.sIFR));

