function LoadAudioPlayer() {
	var so = new SWFObject("/template-images/rebrand-2009/flash/player_mp3_maxi.swf", "audioplayer-flashplayer", "177", "19", "0", "#FFFFFFF");
	so.addParam("quality", "high");
	so.addParam("menu", "false");
	so.addParam("wmode", "transparent");
	so.addParam("FlashVars", "bgcolor2=6E6B00&amp;bgcolor1=ABA800&amp;volume=200&amp;showvolume=1&amp;showstop=1&amp;showloading=autohide&amp;slidercolor1=FFFFFF&amp;slidercolor2=CBCA5F&amp;");
	so.write("audioplayer-placeholder");
}

function PlayMP3File(filename) {
	var player = document.getElementById('audioplayer-flashplayer');
	if(player) {
		player.SetVariable('player:jsUrl', filename);
		player.SetVariable('player:jsPlay', '');
	}
}

function BSOPageLoad(){
	createFlashControl('/upload/flash/homepage_maincontent.swf','promotion-pane','572','184','','','','#000000'); 
}

function OnClickPlaylistEntry(senderLink, filename) {
	// remove the 'selected' class from the currently selected 'li' element in the audio player
	$('#audioplayer li.selected').removeClass('selected');
	// add the 'selected' class to the 'li' element that contains the clicked link
	$(senderLink).parent().addClass('selected');
	PlayMP3File(filename);
}

function SetupHomepageTabs(){
	$("#homepage-tabs #tabs a").each(
		function(index, item){
			var anchor = $(item);
			var id = anchor.parent().attr("id");
			var tab = id.substring(0, id.indexOf("-"));
			anchor.attr("href", "#");
			anchor.click(
				function(){
					ShowTab(tab);
					return false;
				}
			);
		}
	);
	SetupMoreDetailLinks();
}

function ShowTab(requiredTab){
	// set all tabs to unselected
	$("#homepage-tabs #tabs li").each(
		function(index, item){
			var li = $(item);
			if(li.attr("id") == requiredTab + "-tab"){
				li.addClass("selected");
			} else {
				li.removeClass("selected");
			}
		}
	);
	$.get("/processors/BSOLive/HomepageTabContent?tab=" + requiredTab,
		function(data){
			$("#results").replaceWith(data);
			SetupMoreDetailLinks();
		}
	);
}

function SetupMoreDetailLinks(){
	$("#homepage-tabs a.listing-link").each(
		function(index, item){
			var a = $(item);
			a.attr("href", "#");
			var detail = a.parents("li").find(".listing-detail");
			detail.css("display", "none");
			a.click(function(item){
				ShowMoreDetail(item);
				return false;
			});
		}
	);
}

var originalResultsContentHeight = -1;

function ShowMoreDetail(item){
	var isIE6 = ($.browser.msie && $.browser.version.substr(0,1)<7);
	var isIE7 = ($.browser.msie && $.browser.version.substr(0,1)<8);
	var a = $(item.currentTarget);
	var container = $("#results-content");
	var html = a.html();
	var newHtml = "";
	var detail = a.parents("li").find(".listing-detail");
	if(html.indexOf("SHOW") != -1){
		originalResultsContentHeight = container.outerHeight();
		a.toggleClass("hide");
		newHtml = "HIDE";
		detail.css( {
			"padding" : "10px 0 0 0",
			"display" : "block"
		});
		if(isIE6){
			container.css("height", container.outerHeight() + 4);
		}
		if(isIE7 && !isIE6){
			//container.css("height", container.outerHeight() + detail.outerHeight());
		}
	} else {
		var detailHeight = detail.outerHeight();
		a.toggleClass("hide");
		newHtml = "SHOW";
		detail.css("display", "none");
		//container.css("height", container.outerHeight() - 1 - detailHeight);
		if(isIE6){
			container.css("height", originalResultsContentHeight -24);
		}
	}
	a.html(newHtml);
}
