﻿// JScript File

  var trackid;
  var tracktitle;
  var rated;
var btnid;
   var autoplay;
  var noplayyet;
  var isplaying; // used to stop JW Players listner erroniously firing multiple start events? or is it me???
  var d=new Date();
   var timestamp;
  
  function createtimestamp()
  {
   timestamp=d.getTime();
  //alert(timestamp);
  }
        function createBigPlayer() {
            var flashvars = {
                  // file:"mp3s/music-diary/Un Amour.mp3", 
                  // image:"images/front/UnAmour-Single-150.gif",
                 // duration:"586",
                // title:"1",   
                   //autostart:"true",
                    plugins:"ifequalizer-1,tipjar-1",
                  //stretching:"none",
                    backcolor:"#606060",
                     frontcolor:"#FCF010",
                    lightcolor:"#00FF00",
                    screencolor:"#F0F0F0" 
                    
                    
            }
            var params = {
                    wmode:"transparent",
                    allowfullscreen:"true", 
                    allowscriptaccess:"always",
                    allownetworking:"all",
                    volume:"100",
                      gain:"3"
                   
            }
            var attributes = {
                    id:"player1",  
                    name:"player1"
            }
           swfobject.embedSWF("flash/jwplayer/player.swf", "placeholder1", "370", "300", "9.0.115", false, flashvars, params, attributes);
          createtimestamp(); 
        }
  
        function createPlayer() {
            var flashvars = {
                  // file:"mp3s/music-diary/Un Amour.mp3", 
                  // image:"images/front/UnAmour-Single-150.gif",
                 // duration:"586",
                // title:"1",   
                   //autostart:"true",
                    plugins:"ifequalizer-1,tipjar-1",
                  //stretching:"none",
                    backcolor:"#606060",
                     frontcolor:"#FCF010",
                    lightcolor:"#00FF00",
                    screencolor:"#F0F0F0" 
                    
                    
            }
            var params = {
                    wmode:"transparent",
                    allowfullscreen:"true", 
                    allowscriptaccess:"always",
                    allownetworking:"all",
                    volume:"100",
                      gain:"3"
                   
            }
            var attributes = {
                    id:"player1",  
                    name:"player1"
            }
           swfobject.embedSWF("flash/jwplayer/player.swf", "placeholder1", "313", "258", "9.0.115", false, flashvars, params, attributes);
          createtimestamp(); 
        }
 
       function createMiniPlayer() {
            var flashvars = {
                  // file:"mp3s/music-diary/Un Amour.mp3", 
                  // image:"images/front/UnAmour-Single-150.gif",
                 // duration:"586",
                // title:"1",   
                   //autostart:"true",
                    plugins:"ifequalizer-1,tipjar-1",
                  //stretching:"none",
                    backcolor:"#606060",
                     frontcolor:"#FCF010",
                    lightcolor:"#00FF00",
                    screencolor:"#F0F0F0",
                     controlbar:"over"
            }
            var params = {
                    wmode:"transparent",
                    allowfullscreen:"true", 
                    allowscriptaccess:"always",
                    allownetworking:"all",
                    volume:"100",
                    icons:"false"
       
                   
            }
            var attributes = {
                    id:"player1",  
                    name:"player1"
            }
           swfobject.embedSWF("flash/jwplayer/player.swf", "placeholder2", "256", "191", "9.0.115", false, flashvars, params, attributes);
           createtimestamp();
        }
 
var player = null;
    
 function playerReady(thePlayer) 
 {
  player = window.document[thePlayer.id]; 
  addListeners();
   isplaying=0;
  //alert("player ready - "+ap.value);
  clickplaybutton(1);
  
  //dispatchMouseClickEvent('ctl00_ContentMain_play1');//que and play first file
  }

function addListeners() {
	if (player) { 
		player.addModelListener("STATE", "stateListener");
	} else {
		setTimeout("addListeners()",100);
	}
}

function stateListener(obj) { //IDLE, BUFFERING, PLAYING, PAUSED, COMPLETED
	currentState = obj.newstate; 
	previousState = obj.oldstate; 

	//var tmp = document.getElementById("stat");
	//if (tmp) { 
	//	tmp.innerHTML = "current state: " + currentState + 
	//	"<br>previous state: " + previousState; 
	//}

  if ((previousState=="BUFFERING")&&(currentState=="PLAYING"))
  {
        if (isplaying==0)
            { 
                feedback2(trackid,"Play",0) ;
            }
            
        isplaying=1;
             
       autoplay=1; 
        noplayyet=0;
         //alert("Just started playing"); 
  }
  
  if ((previousState=="PLAYING")&&(currentState=="PAUSED"))
  {
        if (isplaying==1)
            { 
             isplaying=2;
            feedback2(trackid,"Pause",0)
            }
         // alert("Paused");
 }
  
  if ((previousState=="PAUSED")&&(currentState=="PLAYING"))
  {
          if (isplaying==2)
                {
                 isplaying=1;
                 feedback2(trackid,"Resume",0)
                 }
        // alert("Resume"); 
  }
  
  if ((previousState=="IDLE")&&(currentState=="COMPLETED"))
  {
          isplaying=0;
          feedback2(trackid,"Complete",0);
          var tmpbtnid=btnid;
          tmpbtnid++;
          //btnid=0;
          //alert("Track Id is : " +tmpbtnid);
          dispatchMouseClickEvent("ctl00_ContentMain_play"+tmpbtnid);
          //Make current playlist item visible in scroll window
          document.getElementById("ctl00_ContentMain_play"+tmpbtnid).focus();
         // alert("Finished"); 
  }
}


function queJW(imagefilename,mediafilename,mediaduration,mediatitle)
{
var lst = new Array();
lst[0] = {
            file:mediafilename,
           image:imagefilename,
            title:mediatitle,  //Use for ID  
            duration:mediaduration
           //backcolor:"#606060",
           //frontcolor:"#FCF010",
           //lightcolor:"#303030",
           //screencolor:"#F0F0F0"
            }
player.sendEvent('LOAD',lst);
}

function queAndPlayJW(mediaid,mediatitle,mediaartist,medialabel,mediadate,mediadescription,imagefilename,mediafilepath,mediadownloadpath,mediaduration,mediadurationstring,associatedproductid,youtube,starcssname,numberofratings,buttonid,litedetails)
{
isplaying=0;

if  ((btnid==buttonid)&&(noplayyet==0))
{
alert("Media is already playing!") //do nothing if already playing
}
else
{

if (btnid)
{
//noplayyet=0;
document.getElementById("ctl00_ContentMain_play"+btnid).className="off"; //Turn off previos selection
}
else
{
//noplayyet=1;
}

var lst = new Array();
btnid=buttonid;
trackid=mediaid;
tracktitle=mediatitle;
rated=0;
lst[0] = {
            file:mediafilepath,
           image:imagefilename,
            title:mediaid,  //Use for ID  
            duration:mediaduration
           //backcolor:"#606060",
           //frontcolor:"#FCF010",
           //lightcolor:"#303030",
           //screencolor:"#F0F0F0"
          
            }        
            
            if (document.all)
            { //not FireFox
             document.getElementById("lbltitle").innerText=mediatitle; 
            document.getElementById("lblvotes").innerText='('+numberofratings+' ratings)'; 
            document.getElementById("lblartist").innerText=mediaartist;
            document.getElementById("lbllabel").innerText=medialabel;
            document.getElementById("lblduration").innerText=mediadurationstring;
            document.getElementById("lbldate").innerText=mediadate; 
            }
            else
            { // Firefox
            document.getElementById("lbltitle").textContent=mediatitle; 
            document.getElementById("lblvotes").textContent='('+numberofratings+' ratings)'; 
            document.getElementById("lblartist").textContent=mediaartist;
            document.getElementById("lbllabel").textContent=medialabel;
            document.getElementById("lblduration").textContent=mediadurationstring;
            document.getElementById("lbldate").textContent=mediadate; 
            }
            
             document.getElementById("ratingstars").setAttribute("class",starcssname);
            //ratingstars.setAttribute("class",starcssname);
              document.getElementById("ratingstars").setAttribute("className",starcssname);//IE
           //ratingstars.setAttribute("className",starcssname);//IE
            if (litedetails==0)
                        {
                                if (youtube==1)
                                                {
                                                document.getElementById("hpldownloadmp3").href=mediadownloadpath.replace('mp4','mp3') ;
                                               
                                               document.getElementById("hpldownloadmp3").onclick=function(){feedback2(associatedproductid,'Download',0);};


                                               //document.getElementById("hpldownloadmp3").onClick="'feedback2("+associatedproductid+",Download,0)'"; 
                                                document.getElementById("hpldownloadmp4").href=mediadownloadpath;
                                                
                                               document.getElementById("hpldownloadmp4").onclick=function(){feedback2(mediaid,'Download',0);};
                                                
                                                document.getElementById("hplyoutube").href=mediafilepath;
                                                
                                                                 if (document.all)
                                                                { //not FireFox  
                                                                 document.getElementById("hpldownloadmp3").innerText="Download MP3";
                                                                 document.getElementById("hpldownloadmp4").innerText="Download MP4" ;
                                                                 document.getElementById("hplyoutube").innerText=mediafilepath;
                                                                }
                                                                else
                                                                { // Firefox
                                                                 document.getElementById("hpldownloadmp3").textContent="Download MP3";
                                                                 document.getElementById("hpldownloadmp4").textContent="Download MP4" ;
                                                                 document.getElementById("hplyoutube").textContent=mediafilepath; 
                                                                } 
                                               } 
                                else{
                                document.getElementById("hpldownloadmp3").href=mediadownloadpath;
                                document.getElementById("hpldownloadmp3").onclick=function(){feedback2(mediaid,'Download',0);};
                                
                                                                 if (document.all)
                                                                { //not FireFox  
                                                                 document.getElementById("hpldownloadmp3").innerText="Download MP3";
                                                                }
                                                                else
                                                                { // Firefox
                                                                 document.getElementById("hpldownloadmp3").textContent="Download MP3";
                                                                }
                                                                
                                        if (associatedproductid==0)
                                        {
                                        }
                                        else
                                        {
                                                document.getElementById("hpldownloadmp4").href=mediadownloadpath.replace('mp3','mp4') ;
                                               document.getElementById("hpldownloadmp4").onclick=function(){feedback2(associatedproductid,'Download',0);};
 
                                                                 if (document.all)
                                                                { //not FireFox  
                                                                 document.getElementById("hpldownloadmp4").innerText="Download MP4" ;
                                                                }
                                                                else
                                                                { // Firefox
                                                                 document.getElementById("hpldownloadmp4").textContent="Download MP4" ;
                                                                } 
                                        }
                                
                                document.getElementById("hplyoutube").href="";
                               document.getElementById("hplyoutube").innerText="";
                                }
                                
                                            if (document.all)
                                            { //not FireFox  
                                             lbldescription.innerText=mediadescription;
                                            }
                                            else
                                            { // Firefox
                                            document.getElementById("lbldescription").textContent=mediadescription; 
                                            }
                             
                    }
player.sendEvent('LOAD',lst);
//var prev=buttonid-1        
        document.getElementById("ctl00_ContentMain_play"+buttonid).className="play";
         noplayyet=1;   
        if  (autoplay==1) 
       {    
 
       player.sendEvent('PLAY');
            
        
            }  
      else
       {
         autoplay=1;
        }   
 

   
} 
}

function mouseisover(celid)
{
        if (celid==btnid)
        {
        }
        else
        {  
            document.getElementById("ctl00_ContentMain_play"+celid).className="on";
        }
}

function mouseisout(celid)
{
        if (celid==btnid)
        {
        }
        else
        {  
            document.getElementById("ctl00_ContentMain_play"+celid).className="off";
        }

}

function setautoplay(apval)
{
    autoplay=apval;
}

function clickplaybutton(thebtnid)
{
dispatchMouseClickEvent('ctl00_ContentMain_play'+thebtnid);//que and play first file
}
 function ratestar(Rating)
               {
               if (rated==0)
                           {
                           if (trackid)
                                       {
                                       if (Rating==1)
                                               {
                                               alert ("Thanks for Rating "+tracktitle+" with "+Rating+" star")
                                               }
                                               else
                                               {
                                              alert ("Thanks for Rating "+tracktitle+" with "+Rating+" stars")
                                               }
                                        
                                       feedback2(trackid,"Rating",Rating) ;
                                       rated=1; 
                                       }
                             }
                   else
                  {
                 alert("You have already rated this item") 
                 }    
               }   

      function feedback2(tid,tstatus,tvalue) //Using GET - this works
                {
                    xmlHttp=GetXmlHttpObject();
                 
                    if (xmlHttp==null)
                                            {
                                                alert ("Browser does not support HTTP Request")
                                                //notify ("Browser does not support HTTP Request")                
                                                return
                                                 } 
                var url="RecieveFeedback.aspx"
                url=url+"?TrackId="+tid+"&TrackStatus="+tstatus+"&TrackValue="+tvalue+"&TimeStamp="+timestamp;
                //xmlHttp.onreadystatechange=function() { if(xmlHttp.readyState==4 )  { notify(xmlHttp.responseText) }}

                xmlHttp.open("GET",url,true)
                xmlHttp.send(null)
                //alert ("That Should Be It! "+url)
                //notify ("That Should Be It! "+url) 
                }

                function GetXmlHttpObject()
                {
                        var objXMLHttp=null
                        if(window.XMLHttpRequest){
                                                                    objXMLHttp = new XMLHttpRequest()
                                                                    }
                        else if (window.ActiveXObject){
                                                                    objXMLHttp = new ActiveXObject("Microsoft.XMLHttp")
                                                                    }
                        return objXMLHttp
                 }
                 
                 function dispatchMouseClickEvent(targetElement)
{
  
document.getElementById(targetElement).onclick();
}

