jQuery.fn.ytplaylist = function(d) {
    var d = jQuery.extend({
    	playlist: '',
        holderId: 'ytvideo',
        playerHeight:'320',
        playerWidth:'547',
        addThumbs:true,
        thumbSize:'small',
        autoPlay:false,
        playOnLoad:false,
        playfirst:0,
        start:0,
        showRelated:false,
        showInfo:true,
        wmode:true,
        iv_load_policy:true,
        hd:false,
        autoHide:true,
        html5:true,
        playerColor:'ffffff',
        playerversion:'&version=2',
        probably_logged_in:true,
        allowFullScreen:true
        },d);
        var e=$(this);
        var f="";
        var g="&rel=0";
        var h="&showinfo=0";
        var j="t";
        var k="";
        var l="";
        var m="";
        var n="";
        var o="&probably_logged_in=0";
        var p="";
        var pl="";
        if(d.showRelated)g="&rel=1";
        if(d.showInfo)h="&showinfo=1";
        if(d.wmode)j="&wmode=opaque";
        if(d.autoHide)k="&autohide=1";
        if(d.allowFullScreen)l="&fs=1";
        if(d.iv_load_policy)m="&iv_load_policy=3";
        if(d.probably_logged_in)o="&probably_logged_in=1";
        if(d.hd)n="&hd=1";
        if("" != d.playlist)pl="&loop=1&playlist=" + d.playlist;
        //console.log(pl);
        function play(a){
        	if(d.autoPlay&&d.playOnLoad)
        		f="&autoplay=1";
        	d.playOnLoad=true;
        	var b='';
        	if(a==false){
        		return b
        	}else{
        		var ppl = pl.replace( a+",", "");
        		ppl = ppl.replace( ","+a, "");
        		var isIE  = navigator.userAgent.search("MSIE") > -1;
        		var isIE7 = navigator.userAgent.search("MSIE 7") > -1;
        		var isIE8 = navigator.userAgent.search("MSIE 8") > -1;
        		if(isIE || isIE7 || isIE8){
	    		    b+='<OBJECT id=myytplayer classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 width="'+d.playerWidth+'" height="'+d.playerHeight+'">';
	    		    b+='<PARAM NAME="FlashVars" VALUE="">';
	        		b+='<PARAM NAME="Movie" VALUE="http://www.youtube.com/v/'+a+'?autoplay=1&fs=1&hl=zh_TW&rel=0&version=3&loop=0&enablejsapi=1&playerapiid=ytplayer">';
	            	b+='<PARAM NAME="Src" VALUE="http://www.youtube.com/v/'+a+'?autoplay=1&fs=1&hl=zh_TW&rel=0&version=3&loop=0&enablejsapi=1&playerapiid=ytplayer">';
	            	b+='<PARAM NAME="WMode" VALUE="Window">';
	        		b+='<PARAM NAME="Play" VALUE="0">';
	    		    b+='<PARAM NAME="Loop" VALUE="-1">';
	    		    b+='<PARAM NAME="Quality" VALUE="High">';
	    		    b+='<PARAM NAME="SAlign" VALUE="LT">';
	    		    b+='<PARAM NAME="Menu" VALUE="-1">';
	    		    b+='<PARAM NAME="Base" VALUE="">';
	    		    b+='<PARAM NAME="AllowScriptAccess" VALUE="always">';
	    		    b+='<PARAM NAME="Scale" VALUE="NoScale">';
	    		    b+='<PARAM NAME="DeviceFont" VALUE="0">';
	    		    b+='<PARAM NAME="EmbedMovie" VALUE="0">';
	    		    b+='<PARAM NAME="BGColor" VALUE="">';
	    		    b+='<PARAM NAME="SWRemote" VALUE="">';
	    		    b+='<PARAM NAME="MovieData" VALUE="">';
	    		    b+='<PARAM NAME="SeamlessTabbing" VALUE="1">';
	    		    b+='<PARAM NAME="Profile" VALUE="0">';
	    		    b+='<PARAM NAME="ProfileAddress" VALUE="">';
	    		    b+='<PARAM NAME="ProfilePort" VALUE="0">';
	    		    b+='<PARAM NAME="AllowNetworking" VALUE="all">';
	    		    b+='<PARAM NAME="AllowFullScreen" VALUE="false">';
	    		    b+='</OBJECT>';
        		}else{
        			b+='<object height="'+(d.playerHeight-3)+'" width="'+d.playerWidth+'" type="application/x-shockwave-flash" id="myytplayer" data="http://www.youtube.com/v/'+a+'?autoplay=0&fs=1&hl=zh_TW&rel=0&version=3&loop=0&enablejsapi=1&playerapiid=ytplayer"><param name="allowScriptAccess" value="always"></object>'
        		}
        		
        		
//        		if(d.html5){
        			//b+='<iframe class="youtube-player" type="text/html" width="'+d.playerWidth+'" height="'+(d.playerHeight-3)+'" src="http://www.youtube.com/embed/'+a+'?version=3&enablejsapi=1'+f+k+g+h+j+o+n+ppl+'" frameborder="0">';b+='</iframe>'
      //  		    b+='<object height="'+(d.playerHeight-3)+'" width="'+d.playerWidth+'" type="application/x-shockwave-flash" id="myytplayer" data="http://www.youtube.com/v/'+a+'?autoplay=1&fs=1&hl=zh_TW&rel=0&version=3&loop=0&enablejsapi=1&playerapiid=ytplayer"><param name="allowScriptAccess" value="always"></object>'
//        		}else{
//        			b+='<object height="'+d.playerHeight+'" width="'+d.playerWidth+'">';
//        			b+='<param name="movie" value="http://www.youtube.com/v/'+a+d.playerversion+f+g+h+l+m+n+ppl+'&version=3&enablejsapi=1&color1=0x'+d.playerColor+'&color2=0x'+d.playerColor+k+'" />';
//        			b+='<param name="wmode" value="transparent" />';
//        			b+='<param name="allowscriptaccess" value="always" />';
//        			b+='<param name="bgcolor" value="#000000" />';
//        			if(d.allowFullScreen){
//        				b+='<param name="allowfullscreen" value="true" /> '
//        			}
//        			b+='<embed src="http://www.youtube.com/v/'+a+d.playerversion+f+g+h+l+m+n+ppl+'&version=3&enablejsapi=1&color1=0x'+d.playerColor+'&color2=0x'+d.playerColor+k+'"';
//        			if(d.allowFullScreen){
//        				b+=' allowfullscreen="true" '}b+='type="application/x-shockwave-flash" wmode="transparent" bgcolor="#000000" allowscriptaccess="always" height="'+d.playerHeight+'" width="'+d.playerWidth+'"></embed>';b+='</object>'
//        		}
        			return b
        	  }
         };
         
         function youtubeid(a){
           if(a==undefined){
             return false
           }else{
             var b=a.match("[\\\\?&]v=([^&#]*)");
             b=b[1];
             return b
           }
         };
         
         var q=$(e).filter(function(a){
           return a==d.playfirst}).addClass('currentvideo').attr('href');
           var divhtml = play(youtubeid(q));
           if(divhtml==""){
        	   divhtml = "<br>尚無資料";
        	   $('#'+d.holderId+'').height( d.playerHeight ).width(d.playerWidth).html(divhtml);
           }else{
        	   $('#'+d.holderId+'').html(divhtml);
           }
           e.click(function(){
               $('#'+d.holderId+'').html(play(youtubeid($(this).attr('href'))));
               $(e).filter('.currentvideo').removeClass('currentvideo');
               $(this).addClass('currentvideo');
               return false;
           });
           
           if(d.addThumbs){
               e.each(function(i){
                 var a=$(this).text();
                 var b=$(this).text().substring(0,35);
                 if(d.thumbSize=='small'){
                     var c='http://img.youtube.com/vi/'+youtubeid($(this).attr('href'))+'/2.jpg'
                 }else{
                     var c='http://img.youtube.com/vi/'+youtubeid($(this).attr('href'))+'/0.jpg'
                 }
                 $(this).empty().html('<img src="'+c+'" onmouseout="clearTimeout(timer)" onmouseover="mousOverImage(this,\''+youtubeid($(this).attr("href"))+'\',\'1\')" />'+a).attr('alt',b)
                 })}};
            function mousOverImage(a,b,c){
            	if(a)imname=a;imname.src="http://img.youtube.com/vi/"+b+"/"+c+".jpg";
            	c++;
            	if(c>3)c=1;
            	timer=setTimeout("mousOverImage(false,'"+b+"',"+c+");",1000);
            };

