/**
 * @author Tor {CreativePark}
 */
jQuery.fn.cpLoader = function(url, options) {
   var container = this;
   var t;
   var interval = 1000;
   var html = '';
   var embed = '';
   
   var settings = jQuery.extend({
     allowScriptAccess: "sameDomain",
	 quality: "high",
	 bgcolor: null,
	 align: "middle",
	 id: null,
	 width: null,
	 height: null,
	 typ: null
   }, options);
   
   if(settings.typ != 'image') {
     html = html + '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
   	 html = html + 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" ';
   
     embed = embed + '<embed type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" ';
     if(settings.id != null) {
   	   html = html + 'id="' + settings.id + '" ';
       embed = embed + 'name="' + settings.id + '" ';	
     }
     if(settings.width != null) {
       html = html + 'width="' + settings.width + '" ';
       html = html + 'height="' + settings.height + '" >';
       embed = embed + 'width="' + settings.width + '" ';
       embed = embed + 'height="' + settings.height + '" ';
     }
     
     if(settings.typ == 'video') {
       flashvars = 'file=' + url + '&h=' + settings.height + '&w=' + settings.width;
       html = html + '<param name="movie" value="/flv/cp_flv_player.swf">';
       embed = embed + 'src="/flv/cp_flv_player.swf" ';
       html = html + '<param name="FlashVars" value="' + flashvars + '" />';
       embed = embed + 'FlashVars="' + flashvars + '" ';
     } else { 
       html = html + '<param name="movie" value="' + url + '">';
       embed = embed + 'src="' + url +'" ';
     }

     if(settings.bgcolor != null) {
       html = html + '<param name="bgcolor" value="' + settings.bgcolor + '">';
       embed = embed + 'bgcolor="' + settings.bgcolor + '" ';
     }
   
     html = html + '<param name="quality" value="' + settings.quality + '">';
     embed = embed + 'quality="' + settings.quality + '" ';
   
     html = html + '<param name="allowscriptaccess" value="' + settings.allowScriptAccess + '">';
     embed = embed + 'allowscriptaccess="' + settings.allowScriptAccess + '" ';

     html = html + '<param name="wmode" value="transparent">';
	 embed = embed + 'wmode="transparent" ';
	 
     embed = embed + 'swliveconnect="true" ><noembed></noembed></embed>';
     html = html + embed + '</object>';
   } else {
   	 interval = 1;
   	 html = html + '<img src="' + url + '" ';
	 if(settings.width != null) {
       html = html + 'width="' + settings.width + '" ';
       html = html + 'height="' + settings.height + '" ';
     }
	 html = html + ' />';
   }
   
   //this.insertHtml = function() {
   	//clearInterval(t);
     var item = container.append(html);	
   //};
   //t = setInterval(this.insertHtml,interval);
  /* if(settings.typ != 'image') {
     $(item).click(function(){
       alert("Thanks for visiting!");
 	 });
   } */
   return this;
 };
 

