$(document).ready(function() {

	// VIDEO
	$("#mediaplayerlist a[@href*=.flv], #mediaplayerlist a[@href*=.mp4], #mediaplayerlist a[@href*=.mov], #mediaplayerlist a[@href*=.FLV], #mediaplayerlist a[@href*=.MP4], #mediaplayerlist a[@href*=.MOV]").click(function() {
		var path = $(this).attr("href");
		
		$("#player").fadeOut("normal", function() {
		
			addVideoPlayer(path, true);
			
			$("#player").hide();
			$("#player").fadeIn("normal");
		});
		// Disable the a link
		return false;
	});
			
	// AUDIO
	$("#mediaplayerlist a[@href*=.mp3], #mediaplayerlist a[@href*=.MP3]").click(function() {
	
		var path = $(this).attr("href");

		$("#player").fadeOut("normal", function() {

			$("#player").children().each(function() {
				$(this).remove();
			});
			$("#player").prepend('<div id="flash"></div>');
			swfobject.embedSWF("/static_media/swf/audioplayer.swf", "flash", "612", "341", "9.0.0", "/static_media/swf/expressinstall.swf", {soundFile: path}, {menu: "false", wmode: "transparent"}, false);
			
			$("#player").hide();
			$("#player").fadeIn("normal");
		});
		
		// Disable the a link
		return false;
	});
			
	// IMAGES
	/*
	$(function() {
		$("#mediaplayerlist a[@href*=.jpg], #mediaplayerlist a[@href*=.JPG], ").lightBox(); // Select all links that contains lightbox in the attribute rel
	});
    */
	
	$("#mediaplayerlist a[@href*=.jpg], #mediaplayerlist a[@href*=.JPG], ").click(function() {
	
		var path = $(this).attr("href");

		$("#player").fadeOut("normal", function() {
			console.log(path);
			$("#mediaplayer").children().each(function() {
				$(this).remove();
			});
			$("#mediaplayer").append('<div id="player"><img src="' + path + '" alt="" /></div>');
			
			$("#player").hide();
			$("#player").fadeIn("normal");
		});
		
		// Disable the a link
		return false;
	});
	

});


function addAudioPlayer(path, auto) {
	$f("player", "/static_media/swf/flowplayer-3.0.3.swf", {
		playlist: ['/static_media/images/content/audioplayer.jpg', path],
		
		clip: {
			autoPlay: auto
		}
	});
	
	$f(0).load();
}


function addVideoPlayer(path, auto) {
	$f("player", "/static_media/swf/flowplayer-3.0.3.swf", {
		plugins: {
			controls: {
				background: '#222222',
				backgroundGradient: 'low',
				bufferColor: '#333333',
				bufferGradient: 'none',
				progressColor: '#666666',
				sliderColor: '#222222',
				sliderGradient: 'none',
				buttonColor: '#222222',
				buttonOverColor: '#666666',
				autoHide: 'always'
			}
		},
		clip: {
			url: path,
			autoPlay: auto,
			//metaData: false, 
			//duration: 161,

			onStart: function() {
				//$("#player").expose({color:"#000000"});
			},
			onFinish: function() {
				//$.unexpose();
			}
		},
		play: {
			label: 'Spill av',
			replayLabel: 'Spill igjen'
		}
	});
	$f(0).load();
}