/* indepth.js: Javascript content for the In-Depth info page */

var deactivateTestimonials = 1;

// -------------------------------------------------------------------------------------------------
// Function that calls other functions after DOM load
// -------------------------------------------------------------------------------------------------
function initPage() {
	videoSelector();
	embedStartingVid();
	videoInfoSlider();
	musicInfoSlider();
	bookInfoSlider();
	musicPlayer();
	//extrasTooltips();
	//extrasButtons();
}

// -------------------------------------------------------------------------------------------------
// Create the functionality for the video switching buttons
// -------------------------------------------------------------------------------------------------
function videoSelector() {

	// array of videos ids to play
	
	//  switchfoot, laurie, ben, bethany, harrison
	
	//var vids = ['1I8J6NRCfFE', 'seWNz5B9Wh8', '9l2yU8YMBPk', '7YR3IqDwXEs', 'Mm8lbtKicKU'];
	var vids = ['flhcZC3Eozw', 'h_dnqhN4yuU', 'Fv_n9fkAPp0', 'DP7UIXc25-A', 'YqpmGnX7ISQ'];
	
	// assign the individual array items to the elements
	for(var i=0;i< $$('.vb').length;i++) {
		$$('.vb')[i].vid = vids[i];
	}
	
	// assign the mouse events
	$$('.vb')
		.addEvent('mouseover', function() {
			this.effect('opacity', {duration: 200, fps: 100}).custom(1, .7);
		})
		.addEvent('mouseout', function() {
			this.effect('opacity', {duration: 500, fps: 100}).custom(.7, 1);
		})
		.addEvent('click', function() {
			playVid(this.vid);
		});	
/*
	// assign the tooltips
	var myTips = new Tips($$('.vb'), {
		maxTitleChars: 50,
		maxOpacity: .9
	});
*/
}


// -------------------------------------------------------------------------------------------------
// Play the selected video clip
// -------------------------------------------------------------------------------------------------
function playVid(id) {
	//var tag = '<object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/' + id + '&autoplay=1"></param><embed src="http://www.youtube.com/v/' + id + '&autoplay=1" type="application/x-shockwave-flash" width="425" height="350"></embed></object>';
	
	//var tag = '<h2>hi there</h2>';
	
	//$('yt').innerHTML = tag;
	//document.getElementById('yt').innerHTML = tag;
	//e('now playing...');
	
	var so = new SWFObject('http://www.youtube.com/v/' + id + '&autoplay=1', "sotester", "447", "350", "8", "#e2e419");
		//so.addVariable("flashVarText", "this is passed in via FlashVars for example only"); // this line is optional, but this example uses the variable and displays this text inside the flash movie
		so.write("yt");
		
	
}

// -------------------------------------------------------------------------------------------------
// Embed an initial video clip in the playback area
// -------------------------------------------------------------------------------------------------
function embedStartingVid() {
	var so = new SWFObject('http://www.youtube.com/v/Fv_n9fkAPp0', "sotester", "447", "350", "8", "#e2e419");
	so.write("yt");
}

// -------------------------------------------------------------------------------------------------
// A MooTools 'slider' for more info on the DVD
// -------------------------------------------------------------------------------------------------
function videoInfoSlider() {
	var mySlider = new Fx.Slide('yt-infoslider', {duration: 1000, transition: Fx.Transitions.quartOut}).hide();
	/*
	var	infoLink = new Element('a').injectBefore($('yt'));

	//var infoLink = $('yt-infolink');
	infoLink.setProperties({
		id: 'yt-infolink',
		'class': 'infolink',
		href: ''
	});

	infoLink.setHTML = 'Less info...';
	//infoLink.injectAfter($('yt-images'));
	*/
	
	$('yt-infolink').addEvent('click', function(evt) {
		evt.preventDefault();
		mySlider.toggle();
	}.bindWithEvent());
	
	/*

	$('yt-infolink').onclick = function() {
		mySlider.toggle(); //toggle the slider up and down.
	}
	*/
}

// -------------------------------------------------------------------------------------------------
// Mootools 'slider' for info on the Music CD
// -------------------------------------------------------------------------------------------------
function musicInfoSlider() {
	var mySlider = new Fx.Slide('music-infoslider', {duration: 1000, transition: Fx.Transitions.quartOut}).hide();

	$('music-infolink').addEvent('click', function(evt) {
		evt.preventDefault();
		mySlider.toggle(); //toggle the slider up and down.
	}.bindWithEvent());
}

// -------------------------------------------------------------------------------------------------
// Mootools 'slider' for info on the Book
// -------------------------------------------------------------------------------------------------
function bookInfoSlider() {
	var mySlider = new Fx.Slide('book-infoslider', {duration: 1000, transition: Fx.Transitions.quartOut}).hide();

	$('book-infolink').addEvent('click', function(evt) {
		evt.preventDefault();
		mySlider.toggle(); //toggle the slider up and down.
	}.bindWithEvent());
}
// -------------------------------------------------------------------------------------------------
// SWFOjbect to contain the music player
// -------------------------------------------------------------------------------------------------
function musicPlayer() {
	var so = new SWFObject('/swf/mp3player.swf', "mp3player", "447", "472", "8", "#ffffff");
	so.addVariable("file", "playlist.xml");
	so.addVariable("showeq", "true");
	so.addVariable("displayheight", "95");
	so.addVariable("volume", "75");
	so.addVariable("autoscroll", "false");
	so.addVariable("height", "480");
	so.addVariable("overstretch", "none");
	so.addVariable("shuffle", "false");
	so.write("music-player");
}

// -------------------------------------------------------------------------------------------------
// Create the Tooltips for the Extras buttons
// -------------------------------------------------------------------------------------------------
function extrasTooltips() {
	var myTips = new Tips($$('.eb'), {
		maxTitleChars: 50,
		maxOpacity: .9
	});
}
/*
function old_extrasButtons() {
	var pages = ['yir.html', 'gift_card.html'];
	for(var i=0;i<$$('.eb').length;i++) {
		$$('.eb')[i].page = pages[i];
	}

	$$('.eb').action({
		onmouseover: function() {
			this.effect('opacity', {duration: 200, fps: 100}).custom(1, .7);
		},
				
		onmouseout: function() {					
			this.effect('opacity', {duration: 500, fps: 100}).custom(.7, 1);
		},
		
		onclick: function() {
		//e('cheese: ' + this.page);
		var myAjax = new Ajax(
		'ajax_templates/' + this.page,
		{method: 'get', update: $('extras-info')}
	);
	myAjax.request();
		}
		
	}); // end action
}

*/

function extrasButtons() {

	var randNum = Math.random();
	var el = $('extras-info');
	var myFader = el.effect('opacity', {duration: 500});
	var pages = ['yir.html', 'gift_card.html'];
	
	for(var i=0;i< $$('.eb').length;i++) {
		$$('.eb')[i].page = pages[i];
	}

		
	$$('.eb')
		.addEvent('click', function(evt) {
		
			 (new Event(evt)).stop() // PreventDefault problem Solved!! another suggestion from Inviz
		
			myFader.chain(function() {
				new Ajax ('ajax_templates/' + this.page, {
					method: 'get',
					onComplete: myFader.custom.pass([0,1], myFader),
					update: el
				}).request();
			}.bind(this)).custom(1,0);
	});
		
		
}

// -------------------------------------------------------------------------------------------------
// Add the init handler to window.onLoad (keep this at the bottom of the file)
// -------------------------------------------------------------------------------------------------

window.addEvent('domready', function() {
	initPage();
});
/*
if(window.addEventListener) {
	window.addEventListener('load', init, false); // W3C DOM
} else if(window.attachEvent) {
	window.attachEvent('onload', init);
}
*/

