//var AUTOPLAY=true;
var TAB_PREFIX = "__";

$(document).ready(function(){
	//window.scrollTo(0,0);

	init_player();

	$('ul#_menu').tabify(on_tab_change, TAB_PREFIX);

	// Lightbox
	$(".page").each(function(){
		//$('a[@rel*=lightbox]').lightBox(); // Not working w/ current jQuery
		$(this).find('.thumb a').lightBox({
			// Override default /images/*.gif pathnames
			imageLoading:	'/static/jquery-lightbox/images/lightbox-ico-loading.gif',
			imageBtnPrev:	'/static/jquery-lightbox/images/lightbox-btn-prev.gif',
			imageBtnNext:	'/static/jquery-lightbox/images/lightbox-btn-next.gif',
			imageBtnClose:	'/static/jquery-lightbox/images/lightbox-btn-close.gif',
			imageBlank:		'/static/jquery-lightbox/images/lightbox-blank.gif',
			containerResizeSpeed: 100
		});
	});

	// Show/hide
	//init_expanders();
});

function init_player(){
	// INIT PLAYER
	var FLOWPLAYER = "/static/flowplayer/flowplayer-3.2.3.swf";
	flowplayer("a.musicplayer", FLOWPLAYER, {
		plugins: {
			audio: {
				url: 'flowplayer.audio-3.2.1.swf'
			},
			controls: {
				//playlist: true,  // Prev/Next buttons
				//url: 'flowplayer.controls-tube-3.1.3.swf',
				fullscreen: false,
				sliderGradient: 'none',
				progressGradient: 'medium',
				backgroundGradient: 'low',
				tooltipColor: '#003300',
				tooltipTextColor: '#ffffff',
				buttonOverColor: '#728B94',
				borderRadius: '0',
				timeColor: '#999999',
				sliderColor: '#000000',
				volumeSliderColor: '#000000',
				timeBgColor: '#000000',
				durationColor: '#ffffff',
				progressColor: '#112233',
				bufferGradient: 'none',
				volumeSliderGradient: 'none',
				buttonColor: '#000000',
				bufferColor: '#445566',
				backgroundColor: '#000044',
				//backgroundColor: '#aedaff',

				//height: 24,
				autoHide: {enabled: false},
				opacity: 1.0
			}
		}
	});
	flowplayer("a.videoplayer", FLOWPLAYER, {
		clip: {
			//autoPlay: false,
			//baseUrl: '/media',
			scaling: 'orig'
		}
	});

	// Attach each player to its playlist (if it has one)
	// NAMING CONVENTION:
	//     player id:   player_NAME
	//     playlist id: player_NAME_playlist
	$("a.musicplayer").each(function(){
		var id=$(this).attr("id");
		var plid="#"+id+"_playlist";
		var pl=$(plid+":first");
		if(pl.length){
			$f(this).playlist(plid, {loop:true});
		}
	});

	/*
	// Autoplay (workaround playlist highlight glitch)
	try {
		if (AUTOPLAY) $("#_playlist > a:eq(0)").click();
	}
	catch (ReferenceError) {
	}
	*/
}


function on_tab_change(hash){
}



//TODO generalize. Options: (elements, initial=2, animate=0)
function init_expanders(){
	var initial=2,
	   	more="More...",
		less="Less...";
	$(".shows").each(function(){
		var extras = $(this).find(".show:gt("+ initial +")");
		if (extras.length){
			extras.hide();
			$(this).find(".show:last")
			.after("<a class=more href='#'>"+ more +"</a>");
		}
	});
	$(".more").click(function(){
		var extras = $(this).parent().find(".show:gt("+ initial +")");
		if (extras.filter(":hidden").length) {
			//extras.slideDown();  // ugly w/ table rows
			extras.show();
			$(this).text(less);
		} else {
			//extras.slideUp();
			extras.hide();
			$(this).text(more);
		}
		return false;
	});
}

