﻿/*
 * Custom Media Player - Developed by Danish Khan 
 */

(
function(d)
{
d.fn.ytchromeless=function(p)
{
var q={
videoWidth:"250",videoHeight:"160",videoIdBase:"ytplayer",params:
{allowScriptAccess:"always",wmode:"transparent"}};
return this.each(
function(r){
var f=d.extend(q,p),g=d(this),s=g.attr("href"),e=g.attr("id")||
f.videoIdBase+r,t=s.substr(31),a=g.wrap('<div class="video-player"></div>').parent(),
h=d('<div class="video-controls"></div>')
.appendTo(a);d('<div class="video"></div>')
.prependTo(a)
.attr("id",e);
var m,n,o,i,j,k,b;a.bind({togglePlay:function()
{a.togglePlay()},
play:function()
{
    a.play()},
pause:function()
{
    a.pause()},
toggleMute:function()
{
    a.toggleMute()},
mute:function()
{
    a.mute()
},
unMute:function()
{
    a.unMute()
},
seek:function()
{
    a.seek()
},
update:function()
{
    a.update()
},
cue:function()
{
    b.cueVideoById(t)
}
});
a.togglePlay=function()
{
j.hasClass("playing")?a.trigger("pause"):a.trigger("play");return false};
a.play=function()
{
    b.playVideo();j.removeClass("paused").addClass("playing").attr("title","Pause")};
    a.pause=function()
    {
        b.pauseVideo();
        j.removeClass("playing").addClass("paused").attr("title","Play")
    };
    a.toggleMute=function()
    {
        i.hasClass("muted")?a.trigger("unMute"):a.trigger("mute");return false
    };
    a.mute=function()
    {
        b.mute();i.addClass("muted").attr("title","Un-Mute")
    };
    a.unMute=function()
    {
        b.unMute();i.removeClass("muted").attr("title","Mute")
    };
    a.seek=function(c)
    {
        c=Math.round(b.getDuration()*c);b.seekTo(c,false)
    };
    a.update=function()
    {
        var l=d(document.getElementById(g));
        var temp=document.getElementById("test").innerHTML;
        
        var temp1=document.getElementsByName('time').item(0).innerHTML;
        var t1=(Math.round(b.getCurrentTime()/60 *100)/100).toFixed(2); 
        var t2=(Math.round(b.getDuration()/60 *100)/100).toFixed(2); 
       
        temp1=t1 +"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + t2;
        if(t1=="0")
            temp1="0:00" +"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" +"0:00";
            
        if(t2=="0")
            temp1="0:00" +"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" +"0:00";
            
//        temp1=Math.round(t1 *100)/100 +"<img src='images/line.jpg'/>" +Math.round(t2 *100)/100;
          
        document.getElementsByName('time').item(0).innerHTML=temp1;
        
        
        
        h=b.getCurrentTime();
        if(b&&b.getDuration){if(b.getPlayerState()===1)a.play();
            else 
        b.getPlayerState()===0&&a.pause();
        if(b.getVideoBytesLoaded()>-1)
        {
            var c=b.getVideoBytesLoaded()/b.getVideoBytesTotal()*100;o.css("width",c+"%")}
        if(b.getCurrentTime()>0)
        {
            c=b.getCurrentTime()/b.getDuration()*100;n.css("left",c+"%")}}
        };
onYouTubePlayerReady=function(c)
{
var l=d(document.getElementById(c)).parent();
setInterval(function(){l.trigger("update")},250);
l.trigger("cue")};a.init=function()
{
swfobject.embedSWF("http://www.youtube.com/apiplayer?&enablejsapi=1&playerapiid="+e,e,f.videoWidth,f.videoHeight,"8",null,null,f.params,{id:e},
function()
{
b=document.getElementById(e)});
a.addControls()};a.addControls=function()
{
j=d("<a/>",
{
href:"#","class":"play-pause",
text:"Play/Pause",title:"Play",
click:function()
{
a.trigger("togglePlay");
return false}}).appendTo(h);i=d("<a/>",
{
href:"#","class":"volume",
text:"Volume",title:"Mute",click:function()
{
a.trigger("toggleMute");
return false}}).appendTo(h);
g.addClass("view-youtube").attr("title","View on YouTube").text("").appendTo(h);
l=d('<span id="time" name="time" class="time">0:00&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0:00</span>').appendTo(h);
k=d("<div/>",{"class":"status",
click:function(c)
{
;c=c.pageX-k.offset().left;var l=k.width();a.seek(c/l)}})
.appendTo(h);m=d('<div class="bar"></div>').appendTo(k);
o=d('<div class="loaded"></div>').
appendTo(m);
n=d('<span class="indicator"></span>').appendTo(m)};
a.init()})}})(jQuery);

