/****************************************************************
 * jQuery Youtube plugin
 ****************************************************************
 * Class for loading Youtube videos and images
 *
 * https://github.com/kilhage/jquery-youtube
 * @creator Emil Kilhage, 2010
 * @version: 1.0
 * @date: 2010-11-14 04:33:30
 * MIT Licensed.
 * ***************************************************************
 * For usage examples, see readme/examples
 ****************************************************************/
(function(e){function g(a){e.youtube.log()&&console.log("jQuery Youtube :: "+a);return null}function h(){this.__init.apply(this,arguments)}function i(){}var l=["image","video"];h.prototype={videoType:"object",iframeBorder:"0",imageOffset:"0",_y:"http://www.youtube.com",containers:{name:"title",id:"href",data:"alt"},__init:function(a,b,d){this.config=e.youtube.config();this.selector=a.selector;for(var c in d)this.config[c]=d[c];this.elements=e(a);this.type=b;var f=this;this.elements.each(function(){f.init(this)})},
init:function(a){this.element=e(a);a={};if(this.dims=this.element.attr(this.containers.data))a=JSON.parse(this.dims);else{a.width=this.element.width();a.height=this.element.height();if(!a.height||!a.width){a.width=this.config.width;a.height=this.config.height;if(!a.height||!a.width)return g(" no dimentions, returns")}}a={width:a.width,height:a.height,id:this.element.attr(this.containers.id)};for(var b in a)if(a[b])this[b]=a[b];else return g(b+" empty, returns");this.name=this.element.attr(this.containers.name);
b='width="'+this.width+'" height="'+this.height+'"';a="setHtmlOfType_"+this.type;this.selector=this.selector.replace("#","").replace(".","");if(this[a])this.html=this[a](b);else return g(a+" is not defined");this.element.replaceWith(this.html);return null},setHtmlOfType_image:function(a){return'<img class="'+this.selector+'" '+this.containers.id+'="'+e.trim(this.id)+'" src="http://img.youtube.com/vi/'+e.trim(this.id)+"/"+this.imageOffset+'.jpg" '+a+" />"},setHtmlOfType_video:function(a){var b=e.trim(this.id)+
"?",d;for(d in this.config)if(this.config[d]){var c=this.config[d];if(c&&e.inArray(typeof c,["string","number","boolean"])!==-1){if(c===false)c="0";else if(c===true)c="1";b+=d+"="+c+"&"}}switch(this.videoType){case "iframe":return'<iframe title="'+this.name+'" '+this.containers.id+'="'+this.selector+'" type="text/html" src="'+this._y+"/embed/"+b+'" '+a+' frameborder="'+this.iframeBorder+'"></iframe>';default:return"<object "+a+' class="'+this.selector+'"><param name="movie" value="'+this._y+"/v/"+
b+'?fs=1&amp;hl=en_US&amp;rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="'+this._y+"/v/"+b+'?fs=1&amp;hl=en_US&amp;rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" wmode="transparent" allowfullscreen="true" '+a+" ></embed></object>"}}};i.prototype={_config:{autohide:"0",autoplay:"0",enablejsapi:"0",version:"4",hd:"1",disablekb:"0",showinfo:"0"},_log:false,getElementHtml:function(a,b,d,c){if(!a||!b)return g(" :: getElementHtml: identifier or value is not set");
var f="id",j=a.replace(".",""),k="";if(j.length<a.length){a=j;f="class"}else if(a.replace("#","").length<a.length)a=a.replace("#","");if(d&&c)k='alt=\'{"width":"'+d+'","height":"'+c+"\"}'";return"<a "+f+'="'+a+'" href="'+b+'"'+k+"></a>"},element:function(a,b,d,c){switch(typeof a){case "string":return this.getElementHtml(a,b,d,c);case "object":b=[];for(var f in a)a[f]&&b.push(this.getElementHtml(f,a[f],d,c));return b;default:return g(" :: element: invalid data type for id")}},config:function(a){if(!a)return this._config;
return this._config=a},log:function(a){if(!a)return this._log;switch(typeof a){case "boolean":this._log=a;break;case "number":case "string":switch(a){case "enable":this._log=true;break;case "disable":this._log=false;break;default:g(a)}}return null}};e.fn.youtube=function(a,b){if(this.length<1)return this;if(typeof b!=="object")b={};a=typeof a!=="string"||e.inArray(a,l)===-1?"video":a.toLowerCase();new h(this,a,b);return e(this.selector)};e.youtube=new i})(jQuery);

