/* 
	pre-fucked: primoz klemensek
	original idea: 
		jMP3 v0.2.1 - 10.10.2006 (w/Eolas fix & jQuery object replacement)
 		an MP3 Player jQuery Plugin (http://www.sean-o.com/jquery/jmp3)
 		by Sean O	
SIMPLE USAGE Example:
* $(youridorclass).jMP3();
*
* ADVANCED USAGE Example:
* $("#sounddl").jmp3({
*   showfilename: "false",
*   backcolor: "000000",
*   forecolor: "00ff00",
*   width: 200
*
* });
***/
jQuery.fn.jvideo = function(passedOptions){
	// hard-wired options
	var playerpath = "/";					// SET THIS FIRST: path to mediaplayer.swf
	var player = "player.swf";					// SET THIS FIRST: path to mediaplayer.swf / player.swf

	// passable options
	var options = {
		"filepath": "",										// path to MP3 file (default: current directory)
		"backcolor": "",									// background color
		"forecolor": "ffffff",								// foreground color (buttons)
		"width": "25",										// width of player
		"repeat": "no",										// repeat mp3?
		"volume": "50",										// mp3 volume (0-100)
		"autostart": "false",								// play immediately on page load?
		"showdownload": "true",								// show download button in player
		"showfilename": "true",								// show .mp3 filename after player
		"allowfullscreen": "true"								// show .mp3 filename after player
	};
	
	// use passed options, if they exist
	if (passedOptions) {
		jQuery.extend(options, passedOptions);
	}
	
	// iterate through each object
	return this.each(function(){
		// filename needs to be enclosed in tag (e.g. <span class='mp3'>mysong.mp3</span>)
		//var filename = options.filepath + jQuery(this).html();
		
		var filename = $(jQuery(this)).attr('href');
		filename = filename.toLowerCase();
		
		
		// pobriši link!
		$(jQuery(this)).attr({title:filename});
		$(jQuery(this)).removeAttr("href");
		
		var VideoHtml = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
		VideoHtml += 'width="' + options.width + '" height="' + options.height + '" ';
		VideoHtml += 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">';
		VideoHtml += '<param name="movie" value="' + playerpath + '' + player + '?';
		VideoHtml += 'showDownload=' + options.showdownload + '&file=' + filename + '&autostart=' + options.autoplay;
		VideoHtml += '&backcolor=' + options.backcolor + '&frontcolor=' + options.forecolor;
		VideoHtml += '&songVolume=' + options.volume + '" />';
		VideoHtml += '<param name="wmode" value="transparent" />';
		VideoHtml += '<param name="allowfullscreen" value="' + options.allowfullscreen + '" />';
		
		VideoHtml += '<embed wmode="transparent" allowfullscreen="' + options.allowfullscreen + '" width="' + options.width + '" height="' + options.height + '" ';
		VideoHtml += 'src="' + playerpath + '' + player + '?'
		VideoHtml += 'showDownload=' + options.showdownload + '&file=' + filename + '&autostart=' + options.autoplay;
		VideoHtml += '&backcolor=' + options.backcolor + '&frontcolor=' + options.forecolor;
		VideoHtml += '&volume=' + options.volume + '" ';
		VideoHtml += 'type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
		VideoHtml += '</object>';
		// don't display filename if option is set
		if (options.showfilename == "false") { jQuery(this).html(""); }
		jQuery(this).prepend(VideoHtml+"&nbsp;");
		
		// Eolas workaround for IE (Thanks Kurt!)
		if(jQuery.browser.msie){ this.outerHTML = this.outerHTML; }
	});
};
