var QuickTip = Class.create();
QuickTip.prototype = {
	initialize: function(qtPanel, qtControlPanel, qtTrigger, qtEndstate) {
		this.qtPanel = $(qtPanel);
		this.qtControlPanel = $(qtControlPanel);
		this.qtTrigger = $(qtTrigger);
		this.qtEndstate = $(qtEndstate);
		this.movieUrl = this.qtTrigger.href;
		this.qtController = null;
		Event.observe(qtTrigger, 'click', this.setupMovie.bindAsEventListener(this));
	},
	
	setupMovie: function(evt) {
		Event.stop(evt);
		var movie = AC.Quicktime.packageMovie('qt-movie', this.movieUrl, {
			width: 640,
			height: 400,
			autoplay: true,
			controller: false,
			cache: true,
			poster: ''
		});
		this.qtEndstate.hide();
		this.qtPanel.innerHTML = '';
		this.qtPanel.appendChild(movie);
		this.qtController = new AC.QuicktimeController(movie, {
			onMoviePlayable: function() {
				this.track('V@S');
				this.qtController.monitorMovie();
				this.qtController.Play();
				setTimeout(function() {
					this.qtController.options.onMovieFinished = this.resetMovie.bind(this);
				}.bind(this),1000);
			}.bind(this)
		});
		this.qtController.render(this.qtControlPanel);
		movie = null;
	},
	
	resetMovie: function() {
		this.track('V@E');
		this.qtController.options.onMovieFinished = null;
		this.qtController.Stop();
		this.qtControlPanel.innerHTML = '';
		this.qtPanel.innerHTML = '';
		this.qtEndstate.down('.text').innerHTML = 'Watch Again';
		var replay = Builder.node('p', { className:'pillbutton replay' }, [
			Builder.node('a', { href:'/ca/business/theater/'}, [
				Builder.node('span', 'View more Quick Tips'),
				Builder.node('b', '&gt;')
			])
		]);
		this.qtEndstate.appendChild(replay);
		this.qtEndstate.show();
	},
	
	track: function(state) {
		if (state == 'V@S') {
			this.order++;
		}

		var movieName = AC.Tracking.pageName() + ' - ' + $('qt-endstate').down('h3').innerHTML.stripTags();
		if (state == 'V@S') {
			movieName = 'V@S: ' + movieName + ' (US)';
			AC.Tracking.trackPage({
				pageName: movieName,
				prop4: this.movieUrl,
				prop6: movieName,
				prop13: movieName
			});
		} else if (state == 'V@E') {
			movieName = 'V@E: ' + movieName + ' (US)';
			AC.Tracking.trackClick({
				prop13: movieName
			}, this, 'o', movieName);
		}
		
	}
}
var heroPromos = [
	'<a href="\/ca\/business\/profiles\/panelsource\/"><img src="http:\/\/images.apple.com\/business\/profiles\/panelsource\/images\/index_hero_panelsource20090701.jpg" width="483" height="245" alt="Panel Source International"></a>',
	'<a href="\/ca\/business\/profiles\/mailwise\/"><img src="\/ca\/business\/images\/index_hero_16_20081215.jpg" width="483" height="245" alt="MailWise"><\/a>',			  
	'<a href="\/ca\/business\/profiles\/ocsd\/"><img src="\/ca\/business\/images\/index_hero_15_20081215.jpg" width="483" height="245" alt="Orange County Sheriffs Department"><\/a>',			  
	'<a href="\/ca\/business\/profiles\/roastingplant\/"><img src="\/ca\/business\/images\/index_hero_14_20081107.jpg" width="483" height="245" alt="Roasting Plant® Coffee Company"><\/a>',
	'<a href="\/ca\/business\/profiles\/kansascoldstorage\/"><img src="\/ca\/business\/images\/index_hero_13_20080917.jpg" width="483" height="245" alt="Kansas Cold Storage"><\/a>',
	'<a href="\/ca\/business\/profiles\/sustainable_harvest\/"><img src="\/ca\/business\/images\/index_hero_11_20080801.jpg" width="483" height="245" alt="Sustainable Harvest"><\/a>',
	'<a href="\/ca\/business\/profiles\/getsatisfaction\/"><img src="\/ca\/business\/images\/index_hero_12_20080813.jpg" width="483" height="245" alt="Get Satisfaction"><\/a>',
	'<a href="\/ca\/business\/profiles\/sustainable_harvest\/"><img src="\/ca\/business\/images\/index_hero_11_20080801.jpg" width="483" height="245" alt="Sustainable Harvest"><\/a>',
	'<a href="\/ca\/business\/profiles\/trek\/"><img src="\/ca\/business\/images\/index_hero_10_20080714.jpg" width="483" height="245" alt="Trek Bicycle Corporation"><\/a>',
	'<a href="\/ca\/business\/profiles\/chapman_cutler\/"><img src="\/ca\/business\/images\/index_hero_9_20080703.jpg" width="483" height="245" alt="Chapman and Cutler, LLP."><\/a>', 
	'<a href="\/ca\/business\/profiles\/aronson\/"><img src="\/ca\/business\/images\/index_hero_7_20080613.jpg" width="483" height="245" alt="Elliot Aronson"><\/a>'
	
];
var imgLoader = new Image();
for(i=0; i<heroPromos.length; i++) {
	imgLoader.src = heroPromos[i].substring(heroPromos[i].indexOf('images/index_hero'), heroPromos[i].indexOf('index_hero')+25);
}

var randomizeWhyMac = [
	'<img src="\/ca\/business\/images\/index_macatwork_numbers20081103.jpg" width="100" height="114" alt="Leopard" class="right">\r<h4>You&#146;ll feel right at home with iWork.<\/h4>\r<p>If you&#146;re used to working with Microsoft Office applications like Word, Excel, and PowerPoint, iWork will feel like home. <a href="\/ca\/business\/macatwork\/" class="more">Learn&nbsp;More<\/a><\/p>',
		
	'<img src="\/ca\/business\/images\/index_macatwork_sharing20081103.jpg" width="100" height="114" alt="Leopard" class="right" style="margin-right:-15px;">\r<h4>Plays well with others.<\/h4>\r<p>Are you a Mac user in a PC world? Don&#146;t worry. The Mac can open most popular files available on PCs like PDFs, JPGs, and Word documents. <a href="\/ca\/business\/macatwork\/#three" class="more">Learn&nbsp;More<\/a><\/p>',
	
	'<img src="\/ca\/business\/images\/index_macatwork_macbookair20081103.jpg" width="100" height="114" alt="Leopard" class="right">\r<h4>Kiss clutter goodbye.<\/h4>\r<p>A Mac is designed to get work done. Fast. With one-of-a-kind features that keep you organized. Take a peek inside any document without having to open its application, using Quick Look. <a href="\/ca\/business\/macatwork\/#five" class="more">Learn&nbsp;More<\/a><\/p>', 
	
	'<img src="\/ca\/business\/images\/index_macatwork_timemachine20081103.jpg" width="100" height="114" alt="Leopard" class="right">\r<h4>Because you can time&nbsp;travel.<\/h4>\r<p>Save your business time by traveling through it. With Mac OS X&#146;s revolutionary new Time Machine, you can retrieve any document—no matter how long ago you deleted it. <a href="\/ca\/business\/macatwork\/#six" class="more">Learn&nbsp;More<\/a><\/p>', 
	
	'<img src="\/ca\/business\/images\/index_macatwork_vmware20081103.jpg" width="100" height="114" alt="Leopard" class="right" style="margin-right:-15px;">\r<h4>You can bring Windows&nbsp;with&nbsp;you.<\/h4>\r<p>Need to run the occasional Windows app? Your new Mac can run Windows XP or Vista natively thanks to Boot Camp software included with Mac OS X. <a href="\/ca\/business\/macatwork\/#seven" class="more">Learn&nbsp;More<\/a><\/p>',
	
	'<img src="\/ca\/business\/images\/index_macatwork_macbookpro20081103.jpg" width="100" height="114" alt="Leopard" class="right">\r<h4>You don&#146;t have to leave your Office.<\/h4>\r<p>Did you know that Word, PowerPoint, and Excel are all made for the Mac too? There&#146;s basically no learning curve, because the programs work the same. <a href="\/ca\/business\/macatwork\/#nine" class="more">Learn&nbsp;More<\/a><\/p>'
];

var randomizePromoTop = [
	'<a href="http:\/\/www.apple.com\/ca\/macbookair\/"><img src="\/ca\/business\/images\/index_heropromo_macbookair.gif" width="73" height="60" alt="Macbook air"><\/a>\r<h3><a href="http:\/\/www.apple.com\/ca\/macbookair\/">Introducing MacBook Air.<\/a><\/h3>\r<p>The world\'s thinnest notebook. <a href="http:\/\/www.apple.com\/ca\/macbookair\/" class="more">Learn&nbsp;More<\/a><\/p>',				 
	'<a href="http:\/\/www.apple.com\/ca\/macosx\/"><img src="\/ca\/business\/images\/index_heropromo_leopard.gif" width="73" height="60" alt="Leopard"><\/a>\r<h3><a href="http:\/\/www.apple.com\/ca\/macosx\/">Leopard.<\/a><\/h3>\r<p>See the most impressive Mac OS X version yet. <a href="http:\/\/www.apple.com\/ca\/macosx\/" class="more">Learn&nbsp;More<\/a><\/p>', 
	'<a href="http:\/\/www.apple.com\/ca\/iwork\/"><img src="\/ca\/business\/images\/index_heropromo_iwork.gif" width="73" height="60" alt="iWork"><\/a>\r<h3><a href="http:\/\/www.apple.com\/ca\/iwork\/">The new iWork \'08.<\/a><\/h3>\r<p>Streamlined word processing, stunning presentations and now spreadsheets. <a href="http:\/\/www.apple.com\/ca\/iwork\/" class="more">Learn&nbsp;More<\/a><\/p>'
];
var randomizePromoBottom = [
	'<a href="\/ca\/business\/solutions\/mobility\/"><img src="\/ca\/business\/images\/index_heropromo_macbookair.gif" width="73" height="60" alt="Mobility"><\/a>\r<h3><a href="\/ca\/business\/solutions\/mobility\/">Mobility.<\/a><\/h3>\r<p>Power Trip. Take your work anywhere. <a href="\/ca\/business\/solutions\/mobility\/" class="more">Learn&nbsp;More<\/a><\/p>',
	'<a href="http:\/\/store.apple.com\/1-800-MY-APPLE\/WebObjects\/canadastore?node=home\/mac\/campaigns\/ms_office_2008_landing"><img src="\/ca\/business\/images\/index_heropromo_office.gif" width="73" height="60" alt="Office 2008"><\/a>\r<h3><a href="http:\/\/store.apple.com\/1-800-MY-APPLE\/WebObjects\/canadastore?node=home\/mac\/campaigns\/ms_office_2008_landing">Office ‘08 for Mac.<\/a><\/h3>\r<p>More tools and greater compatibility with MS Office 2007 for Windows. <a href="http:\/\/store.apple.com\/1-800-MY-APPLE\/WebObjects\/canadastore?node=home\/mac\/campaigns\/ms_office_2008_landing" class="more">Learn&nbsp;More<\/a><\/p>',
	'<a href="http:\/\/www.apple.com\/ca\/iphone\/enterprise\/"><img style="margin-top:9px;" src="\/ca\/business\/images\/index_heropromo_iphone20081111.gif" width="73" height="60" alt="iPhone"><\/a>\r<h3 style="padding-top:12px;"><a href="http:\/\/www.apple.com\/ca\/iphone\/enterprise\/">iPhone.<\/a><\/h3>\r<p>Learn how to integrate iPhone into your business. <a href="http:\/\/www.apple.com\/ca\/iphone\/enterprise\/" class="more">Learn&nbsp;More<\/a><\/p>',
	'<a href="http:\/\/www.apple.com\/ca\/timecapsule\/"><img style="margin-top:8px;" src="\/ca\/business\/images\/index_heropromo_timecapsule.gif" width="73" height="60" alt="Time Capsule"><\/a>\r<h3 style="padding-top:12px;"><a href="http:\/\/www.apple.com\/ca\/timecapsule\/">Time Capsule.<\/a><\/h3>\r<p>A leap forward for backup. <a href="http:\/\/www.apple.com\/ca\/timecapsule\/" class="more">Learn&nbsp;More<\/a><\/p>',
	'<a href="\/ca\/business\/podcasting\/"><img src="http:\/\/images.apple.com\/ca\/business\/images\/index_heropromo_podcasting.png" width="70" height="71" alt="Podcasting"><\/a><h3><a href="\/ca\/business\/podcasting\/">Podcasting.<\/a><\/h3><p>One of the most powerful tools to market your business. <a href="\/ca\/business\/podcasting\/" class="more">Learn More<\/a><\/p>'			 
];


Event.onDOMReady(function() {
	new AC.CrossfadeQueue(heroPromos, 'hero-promo');
	// quicktip movie
	new QuickTip('qt-movie', 'qt-controller', 'qt-trigger', 'qt-endstate');
	
	// solutions swqp
	new AC.ContentSwap('swapnav', 'swapcontent', 'click');

	
	// Why Mac, hero promo and contentfooter randomizers
	if ($('random-tips')) {
		var randNum = Math.floor(Math.random() * (randomizeWhyMac.length));
		$('random-tips').innerHTML = randomizeWhyMac[randNum];
	}
		
	// 	if ($('index-heropromo-top')) {
	// 		var randNum = Math.floor(Math.random() * (randomizePromoTop.length));
	// 		$('index-heropromo-top').innerHTML = randomizePromoTop[randNum];
	// 	}
	if ($('index-heropromo-bottom')) {
		var randNum = Math.floor(Math.random() * (randomizePromoBottom.length));
		$('index-heropromo-bottom').innerHTML = randomizePromoBottom[randNum];
	}
	
	// insert profiles
	if($('profiles')) new ShowProfiles($('profiles'));
});
