

fixOffset = function(){
	if(!$('#modalContainer').length) return;
	if($.browser.msie){
		$('#modalContainer').css('top', (document.documentElement.scrollTop || document.body.scrollTop)+($(window).height()-$('#modalContainer').height())/2+'px');
		$('#modalContainer').css('left', (document.documentElement.scrollLeft || document.body.scrollLeft)+($(window).width()-$('#modalContainer').width())/2+'px');
	} else {
		$('#modalContainer').css('top', ($(window).innerHeight()-$('#modalContainer').height())/2+'px');
		$('#modalContainer').css('left', ($(window).width()-$('#modalContainer').width())/2+'px');
	}
};

$(document).ready(function(){
	$(window).scroll(fixOffset).resize(fixOffset);
});

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);
}



function placePlayer(pid, name)
{
	$('#t'+pid).addClass('track-pause');
	
	var w = 300;

	swfobject.embedSWF("/swf/player.swf", 'track'+pid, w, "13", "8.0.0", false, {
		prw : name,
		prwid : pid,
		p_width : w
	}, { allowScriptAccess: 'always', wmode: 'transparent' }, { });
}

function loadPreview(pid, name)
{
	stopPreview(pid);

	placePlayer(pid, name);
}

function stopPreview(pid) {

	var player = null;
	
	$('a.track-preview').each(function(n) {
		var self = $(this);
		
		var track_id = parseInt($(this).attr('id').substr(1));
		
		if(track_id != pid) {
			$('#t'+track_id).removeClass('track-pause');
			
			player = getFlashMovieObject("track"+track_id);
			
			//if(typeof player == "function") {
				$('#track'+track_id).replaceWith('<div id="track'+track_id+'"></div>');
			//}
		}
	});

}

function initPause(id) {
	stopPreview( id );
}

function initReleasePreview() {
	
	$('a.track-preview').click(function(e) {
		
		e.preventDefault();
		
		var track_id = parseInt($(this).attr('id').substr(1));
		
		if($(this).hasClass('track-pause'))
		{
			stopPreview(0);
		} else {
			if(track_id > 0)
			{ 
				loadPreview(track_id, $(this).attr('rel'));
			}
		}
	});	
}


