/**
 * Video creator is a javascript class that turns all links with given class that have *.flv href into video player 
 * 
 * 
 */
function VideoCreator() {
	var self = this;
	
	this.linksCollection = new Array();
	
	this.config = {
		videoPlayer:			'/externals/player.swf',
		defaultWidth: 			320,
		defaultHeight:			240,
		defaultFlashVersion:	'9',
		
		searchFileExtension: 	'.flv',
		searchLinkClass:		'videoflv'
	}
	
	this.construct = function() {
		self.fetchLinks();
		self.convertLinks();
	}
	
	this.fetchLinks = function() {
		// find all links that contain specific class name
		$("a[class*='" + self.config.searchLinkClass + "']").each( function() {
			// and lead to a video file
			if($(this).attr('href').substr(-4) == self.config.searchFileExtension) {
				self.linksCollection.push($(this));
			}
		})
	}
	
	this.convertLinks = function() {
		for(i = 0; i < self.linksCollection.length; i++) {
			self.createMovieObject(self.linksCollection[i]);
		}
	}
	
	this.createMovieObject = function(linkObject) {
		frameLink 	= linkObject.attr('title');
		movieLink 	= linkObject.attr('href');
		elementId	= linkObject.attr('rel');
		
		linkObject.wrap('<div class="embed_video"></div>');
		linkObject.after('<div id="' + elementId + '">flash video</div>');
		linkObject.remove();
		
		flash = new SWFObject(self.config.videoPlayer, 'flash_'+elementId, self.config.defaultWidth, self.config.defaultHeight, self.config.defaultFlashVersion, "#FFFFFF");
		flash.addParam("allowfullscreen","true");
		flash.addParam("allowscriptaccess","always");
		flash.addParam("flashvars","file=" + movieLink + "&amp;image=" + frameLink + "");
		flash.write(elementId);	
	}

	self.construct();
	
}

// start :)
$(document).ready(function() { new VideoCreator(); });