//player.addControllerListener("PLAY","muteTracker");

//var player = null;
//function playerReady(obj) {
    //alert('the videoplayer has been instantiated');
    //player = document.getElementById(obj['id']);
    //player.addControllerListener("PLAY","playTracker");
//};

var videoclickid = null;
var videosclicked = {};//new Array();

jQuery(document).ready(function(){
    var mfClose=function(hash){
      //$('#videoPlayer' + videoclickid).jqmShow();
      $('#videoPlayer' + videoclickid).css('left','50%');
      hash.w.fadeOut('2000',function(){ hash.o.remove(); }); 
    }
    
    $('.modal_feedback').jqm({trigger:'#viewclick', toTop:true, onHide:mfClose});
    //var player = document.getElementById('mpl');
    //var player;
    function playTracker(obj) { alert('the new play state is: '+obj.state); };
    //player.addControllerListener("PLAY","muteTracker");
    // Close Button Highlighting. IE doesn't support :hover. Surprise?
    $('input.jqmdX')
    .hover(
      function(){ $(this).addClass('jqmdXFocus'); }, 
      function(){ $(this).removeClass('jqmdXFocus'); })
    .focus( 
      function(){ this.hideFocus=true; $(this).addClass('jqmdXFocus'); })
    .blur( 
      function(){ $(this).removeClass('jqmdXFocus'); });

    $('.playvideoclick').click(
        function(){
            //alert('playvideo '+ this.name + ' has been clicked');
            videoclickid = this.name;
            $('#videoPlayer'+videoclickid).vCenter();
            $('#modal_feedback_' + videoclickid).vCenter();
            //current_video_player = $('#player'+videoclickid+'_id');
            //show_modal_feedback();
            });
});


function simpleListener(obj) { //IDLE, BUFFERING, PLAYING, PAUSED, COMPLETED
    alert('Made it to the stateListener');
}

function stateListener(obj) { //IDLE, BUFFERING, PLAYING, PAUSED, COMPLETED
    //alert('Made it to the stateListener');
    currentState = obj.newstate; 
    previousState = obj.oldstate; 

    var tmp = document.getElementById("stat");
    if (tmp) { 
        tmp.innerHTML = "current state: " + currentState + "<br>previous state: " + previousState; 
    }

    if ((currentState == "PLAYING")) {
      if((videoclickid in videosclicked) == false){
        //videosclicked.push(videoclickid);
        videosclicked[videoclickid] = 0;
        $.ajax({url:'/videotutorials/statisticsCallback?id='+videoclickid});
      }
    }



    if ((currentState == "COMPLETED")) {
        show_modal_feedback();        
        //alert('You have reached the end');
        //document.location.href="http://www.longtailvideo.com/players/jw-flv-player/"; 
    }
}


function addListeners() {
        playlist = player.getPlaylist();
        if ((playlist != null) && (playlist != undefined)) { 
            player.addModelListener("STATE", "stateListener");
        } else {
            setTimeout("addListeners()",100);
        }
}

var player = null;
function playerReady(thePlayer) {
    //alert('the videoplayer with id ' + thePlayer.id + ' has been instantiated');
    player = document.getElementById(thePlayer.id);
    addListeners();
}
//<html>
  //<head>
    //<script type="text/javascript" src="swfobject-2.1.js"></script>
    //<script type="text/javascript">function
    //createPlayer(thePlaceholder, thePlayerId, theFile,
    //theAutostart) { var flashvars = { file: theFile, autostart:
    //theAutostart }; var params = { allowfullscreen: 'true',
    //allowscriptaccess: 'always' }; var attributes = { id:
    //thePlayerId, name: thePlayerId };
    //swfobject.embedSWF('player-4.2.80.swf', thePlaceholder, '320',
    //'196', '9.0.124', false, flashvars, params, attributes); };
    //function init() { createPlayer('placeholder1', 'player1',
    //'video1.flv', false); createPlayer('placeholder2', 'player2',
    //'video2.flv', false); createPlayer('placeholder3', 'player3',
    //'video3.flv', false); };</script>
  //</head>
  //<body onLoad="init();">
    //<div id="container1">
      //<a id="placeholder1"
      //href="http://www.macromedia.com/go/getflashplayer">Get the
      //Flash Player to see this player.</a>
    //</div>
    //<div id="container2">
      //<a id="placeholder2"
      //href="http://www.macromedia.com/go/getflashplayer">Get the
      //Flash Player to see this player.</a>
    //</div>
    //<div id="container3">
      //<a id="placeholder3"
      //href="http://www.macromedia.com/go/getflashplayer">Get the
      //Flash Player to see this player.</a>
    //</div>
  //</body>
//</html>
