/**
 * 
 * 
 * 
 */

function YouTubeCreator() {
	var self = this;

	this.linksCollection = new Array();

	this.config = {
		defaultWidth: 			500,
		defaultHeight:			315,
		defaultFlashVersion:	'9',
		searchLinkClass:		'youtubevideo'
	}

	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() {			
                    self.linksCollection.push($(this));
		})
	}

	this.convertLinks = function() {
		for(i = 0; i < self.linksCollection.length; i++) {
                    self.createMovieObject(self.linksCollection[i]);
		}
	}

	this.createMovieObject = function(linkObject) {


                movieTitle 	= linkObject.attr('title');
		movieLink 	= linkObject.attr('href');
                
                var objtext = '<object width="500" height="315">'+
                '<param name="movie" value="'+movieLink+'">'+
                '<param name="allowFullScreen" value="true">'+
                '<param name="allowscriptaccess" value="always">'+
                '<embed src="'+movieLink+'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="500" height="315">'+
                '</object>';
                linkObject.wrap('<div id="nest_'+movieTitle+'"></div>');
                linkObject.remove();
                $('#nest_'+movieTitle).html( objtext );
             
	}

	self.construct();

}
// start :)
$(document).ready(function() {
    new YouTubeCreator();
}
);