	
function sendFlashPlayerEvent(playerCommand) {
	var weavePlayerSWF = getFlashMovieObject("weavePlayer");
	weavePlayerSWF.flashPlayerEvent(playerCommand);
}


function getFlashMovieObject(movieName){
    if (window.document[movieName]){
        return window.document[movieName];
    }
    if (navigator.appName.indexOf("Microsoft Internet")==-1){
        if (document.embeds && document.embeds[movieName])
            return document.embeds[movieName];
    }
    else{
        return document.getElementById(movieName);
    }
}

$(document).ready(function(){
	var controller = $('body').attr('id') || null;

	if (controller != null) {
		FR[controller].init();
	}
	
	/*
	 * Site wide DOM manipulation should be here
	 */
	
	$('a[@rel*=lightbox]').lightBox();
	
	$('a[@rel*=external]').click(function(){
		window.open($(this).attr('href'));
		return false;
	});
		
	$('a[@rel*=music]').click(function(){
		
		var id = $(this).attr('href').replace(/#/, '');
				
		$('#flash-player').remove();
		$('#player').append('<div id="weavePlayer"></div>');
		var flashvars = {};
		flashvars.playOnLoad = "true";
		flashvars.playlistUrl = "/rest/albums/view/" + id;
		flashvars.mp3Url = "/files/Tracks/";
		var params = {};
		params.allowscriptaccess = "sameDomain";
		var attributes = {};
		swfobject.embedSWF("/flash/weavePlayer.swf", "weavePlayer",  "210", "580", "9.0.0", false, flashvars, params, attributes);
		return false;
	});
	
	$('a[@rel*=play]').click(function(){
		sendFlashPlayerEvent('PLAY');
		return false;
	});
	
	var convertDropDowns = (function(){
		$('ol.dropdown').each(function(){
			var $this = $(this), options = [];
			$this.find('li').each(function(i){
				selected = ($(this).hasClass('selected')) ? ' selected="selected"' : '';
				if(i == 1) options.push('<optgroup label="------------">');
				options.push('<option' + selected + ' value="' + $(this).find('a').attr('href') + '">' + $(this).text() + '</option>');
				if(i == ($this.find('li').length - 1)) options.push('</optgroup>');
			});
			
			$this
				.after('<select class="dropdown">' + options.join('') + '</select>')
					.next('select')
					.change(function(){
						window.location = $(this).val();
					})
					.end()
					.remove();
		});
		
	})();
	
	var setcontentHeight = (function(){
		var content = $('div#content'), player = $('div#player');
		if(content.height() > player.height()){
			player.height(content.height() + 10);
		} else {
			content.height(player.height());
		}
		
	})();
	
});