var rootDir = '/web/';
		
var mediaBox;
var bottomLeftBox;
var piecesMenu;
var backToPieceButton;

var navigationWidget;

var fitVideo = false; //true;
var soundElement = null;

function resetBottomRightBox () {
	piecesMenu.hide();
	navigationWidget.hideWidget();
	backToPieceButton.hide();
	$('#descriptionBox').hide();

	$('#extraBox').hide();
	
	if (soundElement){
		soundElement.remove();
		soundElement = null;
	}
}

$(document).ready(function () {
	bottomLeftBox = mediaBox = $('#bottomLeftBox');
	piecesMenu = $('#piecesMenu');
	//navigationBox = $('#navigationBox').hide();
	
	navigationWidget = new NavigationWidget();
	navigationWidget.hideWidget();
	
	backToPieceButton = $('#backToPieceButton').hide();
	//$('#mainMenu').hide();
	
	bottomLeftBox.empty();
	$('<img/>').attr('src', rootDir + 'frontside.jpg').attr('width', '700').appendTo(bottomLeftBox);
		
	$('#mainMenuDetectionArea').hover(
		function () {
			$('#menuLabel').fadeOut('slow', function(){

			});

			$("#mainMenu .mainMenuItem").animate({
				width: "show", opacity: "show"
			}, 500);		
		},
		function () {
			$('#mainMenu .mainMenuItem').animate({
				width: "hide", opacity: "hide"
			}, 'slow', function(){});
			
			$('#menuLabel').fadeIn('slow');
		}
	);
	$('#rightTopBox').click(function () {
		var category = $(this).data('category');
		category.menuClick();
	});

	$('#artistName').click(function () {
		showHome();
		console.log('hei');
	});
	
	$.ajax({
		type: 'GET',
		url: rootDir + 'content.xml',
		dataType: 'xml',
		cache: false,
		async: false,
		success: function(data, textStatus) {
			processContentXML(data);
		}
	});
});

function showHome() {
	mediaBox.empty();
	resetBottomRightBox();

	$('#rightTopBox').empty();
	bottomLeftBox.empty();
	$('<img/>').attr('src', rootDir + 'frontside.jpg').attr('width', '700').appendTo(bottomLeftBox);
}

function processContentXML(xml) {
	$(xml).find('category').each(function (i) {					
		var pieces = [];
		$(this).find('piece').each(function (i) {
			var type = $(this).attr('type');
			var piece;
			if (type == 'htmlPage'){
				//var piece = new HtmlPagePiece($(this).attr('htmlPath'), $(this).attr('path'), $(this).attr('menuString'));
				piece = new HtmlPagePiece($(this));
			}
			else if (type == 'CV'){
				piece = new CVPagePiece($(this));
			}
			else if (type == 'sound'){
				piece = new SoundPiece($(this));
			}
			else { // default type, 'video'
				var descMap = {};
				$(this).find('text').each(function (i) {
					descMap[$(this).attr('name')] = $(this).text();
				});
			
				var images = [];
				
				$(this).find('image').each(function(i){
					var desc;
					var textVar = $(this).attr('text');
					if (textVar) desc = descMap[textVar]
					else desc = $(this).find('caption').text();
					var imageItem = new ImageItem($(this).attr('path'), desc);
					images.push(imageItem);
				});
				
				var videos = [];
				$(this).find('movie').each(function(i){
					var item = new VideoItem($(this));
					videos.push(item);
				});
				$(this).find('bigimage').each(function(i){
					var item = new BigImageItem($(this));
					videos.push(item);
				});
				$(this).find('piecesound').each(function(i){
					var item = new PieceSound($(this));
					videos.push(item);
				});
				
				
				piece = new Piece(images, videos, $(this).attr('path'), $(this).attr('menuString'), $(this).attr('preview'), $(this).attr('previewIndex'));

			}

			pieces.push([$(this).attr('year'), piece]);
		});

		// sort pieces
		function _sort(a, b) {
			return a[0] < b[0] ? 1 : - 1;
		}  
		pieces = pieces.sort(_sort);
		pieces = $.map(pieces, function (a) {
			return a[1];
		});


		
		if ($(this).attr('menuString') == 'Contact') {
			new Contact($(this).text());
		} else {
			var category = new Category(pieces, $(this).attr('path'), $(this).attr('menuString'));
		}
	});
};


function formatText(text) {
	var trimmed = text.replace(/^\s+|\s+$/g, '');
	var formattedText = trimmed.replace(/\n/g, '<br/>');
	return formattedText;
}


/*************************************************************/
function NavigationWidget() {
	this.haha = 'hihi';
	this.widgetBox = $('#navigationBox');
	this.indexAndCountBox = $('<div/>').addClass('indexAndCountBox').appendTo(this.widgetBox);
	this.prevButton = $('<div/>').addClass('prevButton').appendTo(this.widgetBox);
	this.nextButton = $('<div/>').addClass('nextButton').appendTo(this.widgetBox);
}

NavigationWidget.prototype = {
	setup: function(index, count, callback){
		this.index = index;
		this.count = count;
		this.callback = callback;
		
		var _callback = callback;

		var _this = this;
		this.prevButton.unbind().click(function () {
			_this.index = (_this.index-1+_this.count) % _this.count;
			_this.indexAndCountBox.text('' + (_this.index+1) + ' of ' + _this.count);
			_callback.showImage(_this.index);
		});
		this.nextButton.unbind().click(function () {
			_this.index = (_this.index+1) % _this.count;
			_this.indexAndCountBox.text('' + (_this.index+1) + ' of ' + _this.count);
			_callback.showImage(_this.index);
		});
		this.indexAndCountBox.text('' + (this.index+1) + ' of ' + this.count);

	},
	showWidget: function(){this.widgetBox.show();},
	hideWidget: function(){this.widgetBox.hide();}
};

/*************************************************************/
function Contact(text) {
	this.text = text;
	this.menuString = 'Contact';
	var element = $('<div/>').appendTo('#mainMenu');
	element.addClass('mainMenuItem');
	element.data('category', this)
	.text(this.menuString)
	.click(function(){$(this).data('category').menuClick();});
}

Contact.prototype = {
	menuClick: function(){
		mediaBox.empty();
		resetBottomRightBox();
		$('#rightTopBox').empty().text(this.menuString).data('category', this);
		bottomLeftBox.empty();
		//$('<img/>').attr('src', rootDir + 'Marit.contact.jpg').attr('height', '500').appendTo(bottomLeftBox);
		$("#descriptionBox").show().html(this.text);
	}
};

/*************************************************************/


function Category(pieces, path, menuString) {
	this.pieces = pieces;
	this.path = path;
	this.menuString = menuString;
	for (var i=0; i<pieces.length; i++) {
		pieces[i].category = this;
	}
	var element = $('<div/>').appendTo('#mainMenu');
	element.addClass('mainMenuItem');
	element.data('category', this)
	.text(menuString)
	.click(function(){$(this).data('category').menuClick();});
}

Category.prototype = {
	menuClick: function(){
		mediaBox.empty();
		resetBottomRightBox();
		piecesMenu.empty().show();
		var projectPath = this.path;
		var ms = this.menuString;
		
		$('#rightTopBox').empty().text(ms).data('category', this);
		
		var row;
		var previewIndex = 0;
		var previewMap = [];
		$.each(this.pieces, function (i) {						
			var p = this;
			var e = $('<div/>')
			.text(this.menuString)
			.appendTo(piecesMenu)
			.click(function(){
				p.enterSlideMode();			
			});

			if (p.preview) {
				previewMap[p.previewIndex] = [p, e];
				//previewMap.push(p.previewSortkey, p.preview
			}
			
			if (0){//p.preview) {
				if (previewIndex%2 == 0) {
					row = $('<div/>').addClass('row').appendTo(mediaBox);
				}
			
				var thumb = $('<div/>')
				.addClass('thumb')
				.appendTo(row)
				.hover(function () {e.css('color', 'black')}, function(){e.css('color', '')})
				.click(function () {
					p.enterSlideMode();
				});
				
				$('<img/>')
				.attr('src', rootDir + 'material/'+ projectPath + '/' + p.path + '/preview.jpg')
				.appendTo(thumb);
				
				previewIndex ++;
				
				e.hover(function () {
					thumb.css('border', '1px solid gray');
				}, function(){
					thumb.css('border', '');
				});
			}
		});

		$.each(previewMap, function(i, xx) {
		//for (var i = 0; i < 10; i++) { // Kan ha opp til 10 previews
			var xx = previewMap[i];
			if (xx) {
				var p = xx[0];
				var e = xx[1];
				if (previewIndex % 2 === 0) {
					row = $('<div/>').addClass('row').appendTo(mediaBox);
				}
			
				var thumb = $('<div/>')
				.addClass('thumb')
				.appendTo(row)
				.hover(function () {e.css('color', 'black')}, function(){e.css('color', '')})
				.click(function () {
					p.enterSlideMode();
				});
				
				$('<img/>')
				.attr('src', rootDir + 'material/'+ projectPath + '/' + p.path + '/preview.jpg')
				.appendTo(thumb);
				
				previewIndex ++;
				
				e.hover(function () {
					thumb.css('border', '1px solid gray');
				}, function(){
					thumb.css('border', '');
				});
	
			}
		});


	}
};

/*************************************************************/
	
	
function Piece(images, videos, path, menuString, preview, previewIndex) {
	this.path = path;
	this.menuString = menuString;
	this.images = images;
	this.videos = videos;
	this.preview = preview;
	this.previewIndex = previewIndex;
	this.imgIndex = 0;
	for (var i=0; i<images.length; i++) {
		images[i].piece = this;
	}
	for (var i=0; i<videos.length; i++) {
		videos[i].piece = this;
	}
}

Piece.prototype = {
	enterSlideMode : function(){
		resetBottomRightBox();
		navigationWidget.showWidget();
		$('#extraBox').empty();
		$('#extraBox').show();
		
		var descriptionBox = $('#descriptionBox').empty();
		var piece = this;
		navigationWidget.setup(this.imgIndex, this.images.length, this);

		//
		// click on image to view larger.
		
		var div = $('<div/>').text('view large image').data('myObject', this).addClass('actionText').css('margin-bottom', '10px').appendTo($('#extraBox')).click(function(){
			var p = $(this).data('myObject');
			p.showBigImage_NEW2();	
			
		});
		
		//

		for (var i=0; i<this.videos.length; i++){
			var v = this.videos[i];
			var linkString = 'play';
			if (v.linkString) linkString = v.linkString;
			
			v.createDiv().data('myObject', v).addClass('actionText').css('margin-bottom', '10px').appendTo($('#extraBox')).click(function(){
				var v = $(this).data('myObject');
				v.show();
			});
		}
					
		this.showImage(piece.imgIndex);
	},
	showImage: function(index){
		this.imgIndex = index;
		var piece = this;
		$('#descriptionBox').show().html(formatText(this.images[index].description));		
		mediaBox.empty();
		$('<img/>').attr('src', rootDir + 'material/' + this.category.path + '/' + this.path + '/images/' + this.images[index].path + '.jpg').appendTo(mediaBox)
		.css('cursor', 'pointer')
		.click(function(){
			piece.showBigImage_NEW2();
		});
	},
	
	showBigImage_NEW2: function(){
		$('#mainBox').hide();
		$('#helperBoxB').empty();
		
		var piece = this;
		
		$('<img/>').attr('src', rootDir + 'material/' + this.category.path + '/' + this.path + '/images/_largeV2_' + this.images[this.imgIndex].path + '.jpg').click(function(){
			$('#bigImageViewBox').hide();
			$('#mainBox').show();
			piece.enterSlideMode();
		
		}).appendTo('#helperBoxB');
		$('<div/>').text('back').addClass('actionText').css('margin-top','10px').click(function () {
			$('#bigImageViewBox').hide();
			$('#mainBox').show();
			piece.enterSlideMode();
		
		}).appendTo('#helperBoxB');		
		
		
		$('#bigImageViewBox').show();
		
	},	
	
	showBigImage_NEW: function () {
		resetBottomRightBox();
		mediaBox.empty();
		var piece = this;
		
		$('<img/>').attr('src', rootDir + 'material/' + this.category.path + '/' + this.path + '/images/_largeV2_' + this.images[this.imgIndex].path + '.jpg').appendTo(mediaBox);

		$('<div/>').text('back').addClass('actionText').css('margin-top','10px').click(function(){piece.enterSlideMode();}).appendTo(mediaBox);
		
	},
	showBigImage: function(){
		w = window.open('', null, 'top=0, left=0, height=' + screen.height + ',width=' + screen.width);
		//toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no
		
		w.document.writeln('<html><head><title>(close window to go back)</title>');
		
		w.document.writeln('<style type="text/css">body, html {margin: 0px; padding: 0px; height: 100%;};</style>');

		w.document.writeln('</head><body>');		
		w.document.writeln('</body></html>');
		w.document.close();
		
		var imgStr = '<img src="' + rootDir + 'material/' + this.category.path + '/' + this.path + '/images/_largeV2_' + this.images[this.imgIndex].path + '.jpg' + '" />';
		
		$('<table width="100%" height="100%" border="0px" cellpadding="0px" cellspacing="0px"><tr><td align="center"><table border="0px" cellpadding="0px" cellspacing="0px"><tr><td valign="middle">' + imgStr + '</td></tr></table></td></tr></table>').appendTo(w.document.body);
		
		
		//$('<img/>').attr('src', rootDir + 'material/' + this.category.path + '/' + this.path + '/images/_largeV2_' + this.images[this.imgIndex].path + '.jpg').appendTo(w.document.body);
		
		w.focus();	
	}
}

/*************************************************************/


function ImageItem(path, description) {
	this.path = path;
	this.description = description;
}


/*************************************************************/

function VideoItem(xmlNode) {
	this.path = xmlNode.attr('path');
	this.width = xmlNode.attr('width');
	this.height = xmlNode.attr('height');
	this.linkString = xmlNode.attr('linkString');
}
VideoItem.prototype = {
	createDiv : function () {
		if (this.linkString) var linkString = this.linkString
		else var linkString = 'play';
		this.element = $('<div/>').text(linkString);
		return this.element;
	},
	show : function(){
		var piece = this.piece;
		var v = this;
		var path = 'material/' + piece.category.path + '/' + piece.path + '/' + v.path;
		resetBottomRightBox();
		mediaBox.empty();
		
		
		$('<div id="container"/>').appendTo(mediaBox);
		
		var w = v.width;
		var h = v.height;
		
		if (w > 500) {
			var fittedWidth=750;
			var xxx = $('<div/>').text('back').addClass('actionText').css('margin-top','10px').click(function(){piece.enterSlideMode();}).appendTo(mediaBox);
		} else {
			var fittedWidth=500;
			$('#descriptionBox').empty().show();
			$('<div/>').text('back').addClass('actionText').click(function(){piece.enterSlideMode();}).appendTo($('#descriptionBox'));
		}
		
		if (fitVideo) {
			h = h / w * fittedWidth;
			w = fittedWidth;
		}

		jwplayer("container").setup({
			flashplayer: rootDir + "player-licenced.swf",
			file: rootDir + path,
			height: h,
			width: w,
			'controlbar.margin': 0,
			screencolor: '' + this.color,
			autostart: true,
			'controlbar.position': 'none',
			stretching: 'uniform'
		});

		/*
		//$('<a/>').attr('href', "http://www.macromedia.com/go/getflashplayer").text('Get the Flash Player').appendTo($('<div id="container"/>').appendTo(mediaBox))
		var s1 = new SWFObject(rootDir + "player-old.swf","ply",w,h,"9","#FFFFFF");
		s1.addParam("allowfullscreen","true");
		s1.addParam("allowscriptaccess","always");
		//s1.addParam("flashvars","file=amplified_webfilm.flv&image=preview.jpg");
		//s1.addParam("flashvars","file="+path+"&autostart=true&controlbar=none&stretching=uniform&screencolor=FFFFFF");
		s1.addParam("flashvars","file="+path+"&autostart=true&controlbar=none&stretching=uniform&screencolor=FFFFFF"); //&volume=0
		s1.write("container");
		//navigationBox.hide()
		*/
	}
}

/*************************************************************/

function BigImageItem(xmlNode){
	this.path = xmlNode.attr('path');
	this.linkString = xmlNode.attr('linkString');
}
BigImageItem.prototype = {
	createDiv : function(){
		this.element = $('<div/>').text(this.linkString);
		return this.element;
	},
	show : function(){
		var piece = this.piece;
		var v = this;
		var path = 'material/' + piece.category.path + '/' + piece.path + '/' + v.path + '.jpg';
		resetBottomRightBox();
		mediaBox.empty();
		$('<img/>').attr('src', rootDir + path).appendTo(mediaBox);
		var xxx = $('<div/>').text('back').addClass('actionText').css('margin-top','10px').click(function(){piece.enterSlideMode();}).appendTo(mediaBox);	
	}
}

/*************************************************************/

function PieceSound(xmlNode){
	this.path = xmlNode.attr('path');
	this.linkString = xmlNode.attr('linkString');
}
PieceSound.prototype = {
	createDiv : function(){
		this.element = $('<div/>').text(this.linkString);
		return this.element;
	},
	show : function(){
		if (this.element.text() == 'play sound'){
			this.element.text('stop sound');
			var path = 'material/' + this.piece.category.path + '/' + this.piece.path + '/' + this.path;
			
			var path = this.path;

			
			soundElement = $.sound.play(path, {timeout: 140000});
			
			//this.xxx.remove()
			//alert(this.xxx)
		}
		else {
			this.element.text('play sound');
			if (soundElement){
				soundElement.remove();
				soundElement = null;
			}
		}		
	}
}

/*************************************************************/

function getXml(path){
	var resultXml
	$.ajax({
		type: 'GET',
		url: path,
		dataType: 'xml',
		cache: false,
		async: false,
		success: function(xml, textStatus){
			resultXml = xml;
		}
	});
	return resultXml;
}

function CVPagePiece(xmlNode){
	this.htmlPath = xmlNode.attr('htmlPath');
	this.path = xmlNode.attr('path');
	this.menuString = xmlNode.attr('menuString');
	this.processedContent = null;
}
CVPagePiece.prototype = {
	enterSlideMode : function(){
		mediaBox.empty();
		resetBottomRightBox();
		$('#descriptionBox').empty().show().html(this.menuString);
		var path = 'material/' + this.category.path + '/' + this.path + '/' + this.htmlPath;
		var listBox = $('<div id="listBox" class="scroll-pane"/>').appendTo(mediaBox);
		listBox.css('width', 500).css('height', 500);
		
		if (!this.processedContent){
			var xml = getXml(rootDir + path);
			var processedContent = $('<div/>');
			this.processedContent = processedContent;
			//this.processedContent = listBox;
			//var processedContent = listBox;

			$(xml).find('category').each(function (i) {
				var cat = $(this);
				//var catDiv = $('<div/>').addClass('cvCategoryBox').appendTo(listBox);
				var catDiv = $('<div/>').addClass('cvCategoryBox').appendTo(processedContent);

				
				$('<div/>').addClass('category').text(cat.attr('label')).appendTo(catDiv);
				
				cat.find('entry').each(function(i){
					var entryDiv = $('<div/>').addClass('cvEntry').appendTo(catDiv);
					var textDiv = $('<div/>').addClass('cvText').html($(this).text()).appendTo(entryDiv);
					var dateDiv = $('<div/>').addClass('cvDate').text($(this).attr('date')).appendTo(entryDiv);				
				});
				$('<div/>').addClass('cvDummyEntryHack').appendTo(catDiv);			
			});
		}
		this.processedContent.appendTo(listBox);
		
			
		listBox.jScrollPane();
		
		$('<div/>').data('myObject', this).addClass('actionText').css('margin-top','40px').text('Printable version').appendTo($('#descriptionBox')).click(function(){
			$(this).data('myObject').openWindowWithPrintableVersion();
		});
		
	},
	
	openWindowWithPrintableVersion : function(){
		w = window.open('', null, "width=700, toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes");
		w.document.writeln('<html><head><title>Marit Følstad - CV</title>');
		
		
		w.document.writeln('<style type="text/css">' +
		'body {font-family: arial,verdana,helvetica,sans-serif; padding-left: 30px;}' +
		'.cvCategoryBox {clear: both; margin:0px; padding: 0px;}' +
		'.category {margin-bottom: 6px; font-size: 18px; font-weight: 900; clear: both;}' +
		'.cvEntry {clear: both; font-size: 14px; padding-top: 5px;}' +
		'.cvDummyEntryHack {line-height: 0px; height: 20px; width: 100px; clear: both;}' +
		'.cvText {float: left; width: 500px;}' +
		'.cvDate {float: left; margin-left: 40px;}' +
		'</style>');
		
		
		w.document.writeln('</head><body>');
		w.document.writeln('<div style="text-align: center">Marit Følstad<br/>CV</div><br/><br/>');
		
		w.document.writeln(this.processedContent.html());
		
		w.document.writeln('</body></html>');
		w.document.close();
		//alert(this.processedContent.clone().html());
		//this.processedContent.clone().appendTo(w.document.body)
		w.focus();
	}
}

function HtmlPagePiece(xmlNode){
	this.htmlPath = xmlNode.attr('htmlPath');
	this.path = xmlNode.attr('path');
	this.menuString = xmlNode.attr('menuString');
	this.xml = null;
}
HtmlPagePiece.prototype = {
	enterSlideMode : function(){
		mediaBox.empty();
		resetBottomRightBox();
		
		var path = 'material/' + this.category.path + '/' + this.path + '/' + this.htmlPath;
		var listBox = $('<div id="listBox" class="scroll-pane"/>').appendTo(mediaBox);
		listBox.css('width', 500).css('height', 500);
				
		if (!this.xml) this.xml = getXml(rootDir + path);
		$('<div/>').html($(this.xml).find('body').text()).appendTo(listBox);
		$('<div/>').css('height', '10px').appendTo(listBox); /*To be sure that all text is accessible in the scroll pane*/
		listBox.jScrollPane();

		var wrapBox = $('<div/>').css('width', '160px').html($(this.xml).find('info').text())
		.appendTo($('#descriptionBox').empty().show());


		$('<div/>').data('myObject', this).addClass('actionText').css('margin-top','40px').text('Printable version').appendTo($('#descriptionBox')).click(function(){
			$(this).data('myObject').openWindowWithPrintableVersion();
		});
	},
	openWindowWithPrintableVersion : function(){
		w = window.open('', null, "width=700, toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes");
		
		w.document.writeln('<html><head><title>' + $(this.xml).find('title').text() + '</title>');
		
		w.document.writeln('<style type="text/css">' + 'body {font-size: 18px;} .textBibliography {font-size: 14px;} .textAboutWriter {font-size: 14px;} .textMainTitle {font-size: 30px;} .textMain {line-height: 22px;}' + '</style>');
		
		w.document.writeln('</head><body>');
		w.document.writeln($(this.xml).find('info').text() + '<br/><br/>');
		w.document.writeln('<div class="textMain">' + $(this.xml).find('body').text() + '</div>');
		w.document.writeln('</body></html>');
		//<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
		w.document.close();
		w.focus();
		
	}
}



function playerReady(obj) {
	//alert('the videoplayer '+obj['id']+' has been instantiated');
	//player = document.getElementById(obj['id']);
};
function SoundPiece(xmlNode){
	this.path = xmlNode.attr('path');
	this.menuString = xmlNode.attr('menuString');
	this.soundFile = xmlNode.attr('soundFile');
	this.color = xmlNode.attr('color');
	this.description = xmlNode.find('caption').text();
	this.preview = xmlNode.attr('preview');
	this.previewIndex = xmlNode.attr('previewIndex');
}
SoundPiece.prototype = {
	enterSlideMode : function(){
		mediaBox.empty();
		resetBottomRightBox();
		
		$('#descriptionBox').empty().show().html(formatText(this.description));
		var path = 'material/' + this.category.path + '/' + this.path + '/' + this.soundFile + '.mp3';


		if (1) {
		$('<div id="container"/>').appendTo(mediaBox);

		jwplayer("container").setup({
			flashplayer: rootDir + "player-licenced.swf",
			file: rootDir + path,
			height: 64,
			width: 500,
			'controlbar.margin': 20,
			screencolor: '' + this.color,
			backcolor: '000000',
			frontcolor: 'FFFFFF',
			autostart: false,
			'controlbar.position': 'over',
			icons: false,
			provider: 'sound',
			'controlbar.idlehide': 'false'
		});
		} else {
		

		
		$('<a/>').attr('href', "http://www.macromedia.com/go/getflashplayer").text('Get the Flash Player').appendTo($('<div id="container"/>').appendTo(mediaBox));

		var s1 = new SWFObject(rootDir + "player-old.swf","ply","500","60","9","#"+this.color);
		s1.addParam("allowfullscreen","false");
		s1.addParam("allowscriptaccess","always");
		//s1.addParam('wmode','opaque');
		s1.addParam("flashvars","file=" + rootDir +path+ "&screencolor=#" +this.color+"&backcolor=000000&icons=false&autostart=false&controlbar=over&type=sound&frontcolor=FFFFFF");
		
		s1.write("container");
		
		}



		// gammelt:
		
		//alert(path)
//&autostart=true&controlbar=none&stretching=none&
//s1.addParam('flashvars','file=http://www.jeroenwijering.com/upload/bunny.mp3&duration=33');


		/*
		//alert(s1);
		var player = document.getElementById('ply');
		//alert(player);
		//player.sendEvent("PLAY","true");
		//s1.sendEvent("PLAY","true");


		var pnav = $('<div/>').css({'border': '0px solid black', 'margin-top': '30px', 'float': 'left'}).appendTo('#descriptionBox');
		var button = $('<div/>').css({'width': '30px', 'height': '30px', 'float': 'left',
				//'background-color':'yellow',
				'background-image': 'url(play_navigation_icons.png)',
				'background-repeat': 'no-repeat',
				'background-position': '-19px -168px' //-118px
		
		}).appendTo(pnav)
		.click(function(){alert('hei');
			var player = document.getElementById('ply');
			player.sendEvent("PLAY","true");
		})
		;
		$('<div/>').css({'width': '30px', 'height': '30px', 'float': 'left',
				'background-image': 'url(play_navigation_icons.png)',
				'background-repeat': 'no-repeat',
				'background-position': '-19px -068px'
		}).appendTo(pnav);
		$('<div/>').css({'width': '30px', 'height': '30px', 'float': 'left',
				'background-image': 'url(play_navigation_icons.png)',
				'background-repeat': 'no-repeat',
				'background-position': '-19px -268px'
		}).appendTo(pnav);
		*////////
	}
}

