window.addEvent('domready', function(){	
	
	// marquee opacity caused text to fade in/out on Mac FF. So, we set body opacity to 0.99999 which seemed to fix it. 
	var ua = navigator.userAgent.toLowerCase();
	if ((ua.indexOf('mac') != -1) && (window.gecko)){
	    (document.body).setStyle('opacity', '0.99999');
	}	
	
	// does not work in safari 2
	// adding flash in the modal window is broken
	marquee = new noobSlide({
		box: $('mast'),
		items: $ES('span','mast'),
		size: 556,
		handles: $ES('span','scroll-marquee'),
		onWalk: function(currentItem, currentHandle){			
			this.handles.each(function(item){
				item.removeClass('active');
			});	
			currentHandle.addClass('active');
		},
		buttons: {
			previous: $('control-prev'),
			stop: $('control-stop'),
			play: $('control-play'),
			next: $('control-next')
		},
		autoPlay: true,
		interval: 6000,
		duration: 1500
	});	
	
	//omniture thumbnail click tracking
	$$('#scroll-marquee .thumb-marquee').each(function(item, index){
		item.addEvent('click', function(e){
			var split = this.getProperty('rel').split('|');
			linkCode(this, split[0], split[1]);
		});
	});
	
	if(!window.webkit419){
		// flash video intro
		var cookie = new Hash.Cookie('vegasMusic', {duration: 14}); // set a duration if we don't want it to expire with session
		var showIntro = cookie.get('showIntro');
		if(showIntro == null){
			cookie.set('showIntro', true);
			showIntro = true;
		}
		if(showIntro){
			cookie.set('showIntro', false);
			modal = new Modal({
				hasClose: false,
				transitionDuration: 10
			});
			
			var introVideo = new Element('div').setProperty('id', 'music-intro');
			var so = new SWFObject('/images/play/music/intro/MusicIntroPlayer.swf', 'intromovie', 936, 362, 8, '#000000');
			so.addParam('quality', "high");
			//so.addParam('wmode', "transparent");
			so.addParam('play', 'true');
			so.addVariable('vidPath1', 'MusicVid1.flv');
			so.addVariable('vidPath2', 'MusicVid2.flv');
			so.addVariable('vidPath3', 'MusicVid3.flv');
			
			// For FF Mac: stop slideshow to prevent flickering
			marquee.stop();
			
			so.write(introVideo);
			
			// give the page a little bit to render before showing intro
			(function(){
				modal.show(introVideo);
			}).delay(500);
		}
	}

	// events to toggle play/pause controls
	$('control-stop').addEvent('click', function(){
		this.setStyle('display', 'none');
		$('control-play').setStyle('display', 'block');
		marquee.autoPlay = false;
	});
	$('control-play').addEvent('click', function(){
		this.setStyle('display', 'none');
		$('control-stop').setStyle('display', 'block');
		marquee.autoPlay = true;
	});
	
	// fix for links
	$('frame').addEvent('click', function(e){
		new Event(e).stop();	
		var currentItem = marquee.items[marquee.currentIndex];
		var anchor = currentItem.getElement('a');
		var href = anchor.getProperty('href');
		var analytics = (anchor.getProperty('rel')||"null|null").split('|');
		linkCode(anchor, analytics[0], analytics[1]);
		if (anchor.getProperty("target") && anchor.getProperty("target").toLowerCase()=="_blank") window.open(href);
		else document.location = href;
	});	
		
	/* Enable span.thumb-marquee:hover on IE6 */
	if(window.ie6) {
		$$('span.thumb-marquee').addEvents({
			mouseover : function(){ this.addClass('ie6-hover'); },
			mouseout : function(){ this.removeClass('ie6-hover'); }
		});
	}
});

// call back function for flash intro
function hideIntro(){
	modal.hide();
	// resume slide show if it exists
	if(marquee){ 
		marquee.play(6000,'next',true);
	}
			
}