  $(function(){
  
    $.initWindowMsg();
	var popup; 
	function playerPopUp(index){
    popup = window.open("player.php?index1="+index,"playerPop","width=278,height=390, location=no, menubar=no, scrollbars=no, status=no, toolbar=no");
    $(window).focus();
    
  //  $(window).unload(function() {
//    popup.close();
//    });
     
    }
    
   
    
    
    $.windowMsg("PlayTimeLocal", function(message) {
 		 $('#jplayer_play_time').text(message);
	});
    $.windowMsg("PlayBar", function(message) {
		$('#jplayer_load_bar').css('width',message);
	});
    $.windowMsg("LoadBar", function(message) {
		$('#jplayer_load_bar').width(message);
	});   
     $.windowMsg("PlayNext", function(message) {
		$("#jplayer_next").click();
	});
    $.windowMsg("PlayPrevious", function(message) {
		$("#jplayer_previous").click();
	});
    $.windowMsg("PlayConfig", function(message) {
        playListConfig( message );
	});
    $.windowMsg("Play", function(message) {
        $("#jplayer_play").click();
        playerPopUp(message);
	});  
    $.windowMsg("Pause", function(message) {
        $("#jplayer_pause").click();
	});
  
    
    
    
	var playItem = 0;
    var myPlayList = [{name:"DIAMONDS",mp3: "http://www.thecabriolets.com/mp3/diamonds_ok.mp3"},
{name:"SHINNING",mp3: "http://www.thecabriolets.com/mp3/shinning.mp3"},
{name:"CREPUSCULAR",mp3: "http://www.thecabriolets.com/mp3/crepuscular_master.mp3"},
{name:"FAST&SLOW",mp3: "http://www.thecabriolets.com/mp3/fast_and_slow_master.mp3"},
{name:"NOW & HERE",mp3: "http://www.thecabriolets.com/mp3/8._now_&_here.mp3"},
{name:"GOOD DAY",mp3: "http://www.thecabriolets.com/mp3/good_day_master.mp3"},
{name:"CLOSE",mp3: "http://www.thecabriolets.com/mp3/10._close.mp3"},
{name:"CLASSIFIEDS",mp3: "http://www.thecabriolets.com/mp3/3.classifieds.mp3"},
{name:"PYROMANIAC",mp3: "http://www.thecabriolets.com/mp3/7._pyromaniac.mp3"},
{name:"BLACKMAIL",mp3: "http://www.thecabriolets.com/mp3/2._blackmail.mp3"},
{name:"TENDERIZER",mp3: "http://www.thecabriolets.com/mp3/9._tenderizer.mp3"},
{name:"BEAUTY IN VOGUE",mp3: "http://www.thecabriolets.com/mp3/12._beauty_in_vogue.mp3"}]; 
      var jpPlayTime = $("#jplayer_play_time");
      var jpTotalTime = $("#jplayer_total_time");
        $("#jquery_jplayer").jPlayer({
    volume:  100,
    ready: function() {
        displayPlayList();
       // playListInit();       
    },
    oggSupport: false
  })
  function displayPlayList() {
		$("#jplayer_playlist ul").append("<li id='jplayer_playlist_item_"+0+"'><a href='javascript:;'><b>4:48</b>"+ myPlayList[0].name +"</a></li>");
      $("#jplayer_playlist_item_"+0).data("index",0).click( function() {
      var index = $(this).data("index");

      if (playItem != index) {
        	playListChange( index );
        } else {
          $("#jquery_jplayer").jPlayer("play");
          $("#jplayer_play_time").append("<h6>"+ myPlayList[0].name +"</h6>");
        }

        
      });
	$("#jplayer_playlist ul").append("<li id='jplayer_playlist_item_"+1+"'><a href='javascript:;'><b>3:07</b>"+ myPlayList[1].name +"</a></li>");
      $("#jplayer_playlist_item_"+1).data("index",1).click( function() {
      var index = $(this).data("index");

      if (playItem != index) {
        	playListChange( index );
        } else {
          $("#jquery_jplayer").jPlayer("play");
          $("#jplayer_play_time").append("<h6>"+ myPlayList[1].name +"</h6>");
        }

        
      });
	$("#jplayer_playlist ul").append("<li id='jplayer_playlist_item_"+2+"'><a href='javascript:;'><b>3:52</b>"+ myPlayList[2].name +"</a></li>");
      $("#jplayer_playlist_item_"+2).data("index",2).click( function() {
      var index = $(this).data("index");

      if (playItem != index) {
        	playListChange( index );
        } else {
          $("#jquery_jplayer").jPlayer("play");
          $("#jplayer_play_time").append("<h6>"+ myPlayList[2].name +"</h6>");
        }

        
      });
	$("#jplayer_playlist ul").append("<li id='jplayer_playlist_item_"+3+"'><a href='javascript:;'><b>3:33</b>"+ myPlayList[3].name +"</a></li>");
      $("#jplayer_playlist_item_"+3).data("index",3).click( function() {
      var index = $(this).data("index");

      if (playItem != index) {
        	playListChange( index );
        } else {
          $("#jquery_jplayer").jPlayer("play");
          $("#jplayer_play_time").append("<h6>"+ myPlayList[3].name +"</h6>");
        }

        
      });
	$("#jplayer_playlist ul").append("<li id='jplayer_playlist_item_"+4+"'><a href='javascript:;'><b>3:56</b>"+ myPlayList[4].name +"</a></li>");
      $("#jplayer_playlist_item_"+4).data("index",4).click( function() {
      var index = $(this).data("index");

      if (playItem != index) {
        	playListChange( index );
        } else {
          $("#jquery_jplayer").jPlayer("play");
          $("#jplayer_play_time").append("<h6>"+ myPlayList[4].name +"</h6>");
        }

        
      });
	$("#jplayer_playlist ul").append("<li id='jplayer_playlist_item_"+5+"'><a href='javascript:;'><b>4:13</b>"+ myPlayList[5].name +"</a></li>");
      $("#jplayer_playlist_item_"+5).data("index",5).click( function() {
      var index = $(this).data("index");

      if (playItem != index) {
        	playListChange( index );
        } else {
          $("#jquery_jplayer").jPlayer("play");
          $("#jplayer_play_time").append("<h6>"+ myPlayList[5].name +"</h6>");
        }

        
      });
	$("#jplayer_playlist ul").append("<li id='jplayer_playlist_item_"+6+"'><a href='javascript:;'><b>3:44</b>"+ myPlayList[6].name +"</a></li>");
      $("#jplayer_playlist_item_"+6).data("index",6).click( function() {
      var index = $(this).data("index");

      if (playItem != index) {
        	playListChange( index );
        } else {
          $("#jquery_jplayer").jPlayer("play");
          $("#jplayer_play_time").append("<h6>"+ myPlayList[6].name +"</h6>");
        }

        
      });
	$("#jplayer_playlist ul").append("<li id='jplayer_playlist_item_"+7+"'><a href='javascript:;'><b>4:26</b>"+ myPlayList[7].name +"</a></li>");
      $("#jplayer_playlist_item_"+7).data("index",7).click( function() {
      var index = $(this).data("index");

      if (playItem != index) {
        	playListChange( index );
        } else {
          $("#jquery_jplayer").jPlayer("play");
          $("#jplayer_play_time").append("<h6>"+ myPlayList[7].name +"</h6>");
        }

        
      });
	$("#jplayer_playlist ul").append("<li id='jplayer_playlist_item_"+8+"'><a href='javascript:;'><b>4:22</b>"+ myPlayList[8].name +"</a></li>");
      $("#jplayer_playlist_item_"+8).data("index",8).click( function() {
      var index = $(this).data("index");

      if (playItem != index) {
        	playListChange( index );
        } else {
          $("#jquery_jplayer").jPlayer("play");
          $("#jplayer_play_time").append("<h6>"+ myPlayList[8].name +"</h6>");
        }

        
      });
	$("#jplayer_playlist ul").append("<li id='jplayer_playlist_item_"+9+"'><a href='javascript:;'><b>2:49</b>"+ myPlayList[9].name +"</a></li>");
      $("#jplayer_playlist_item_"+9).data("index",9).click( function() {
      var index = $(this).data("index");

      if (playItem != index) {
        	playListChange( index );
        } else {
          $("#jquery_jplayer").jPlayer("play");
          $("#jplayer_play_time").append("<h6>"+ myPlayList[9].name +"</h6>");
        }

        
      });
	$("#jplayer_playlist ul").append("<li id='jplayer_playlist_item_"+10+"'><a href='javascript:;'><b>3:32</b>"+ myPlayList[10].name +"</a></li>");
      $("#jplayer_playlist_item_"+10).data("index",10).click( function() {
      var index = $(this).data("index");

      if (playItem != index) {
        	playListChange( index );
        } else {
          $("#jquery_jplayer").jPlayer("play");
          $("#jplayer_play_time").append("<h6>"+ myPlayList[10].name +"</h6>");
        }

        
      });
	$("#jplayer_playlist ul").append("<li id='jplayer_playlist_item_"+11+"'><a href='javascript:;'><b>2:26</b>"+ myPlayList[11].name +"</a></li>");
      $("#jplayer_playlist_item_"+11).data("index",11).click( function() {
      var index = $(this).data("index");

      if (playItem != index) {
        	playListChange( index );
        } else {
          $("#jquery_jplayer").jPlayer("play");
          $("#jplayer_play_time").append("<h6>"+ myPlayList[11].name +"</h6>");
        }

        
      });
}
//  function playListInit(autoplay) {
//    if(autoplay) {
//    	playListChange( playItem );
//    } else {
//    playListConfig( playItem );
//    }
//  }

  	$("#jplayer_play").click( function() {
    	$(this).hide();
        $("#jplayer_pause").show();
        playListChange(playItem);
	});
    
    $("#jplayer_pause").click( function() {
    	$(this).hide();
        playerPopUp(-1);
        return false;
	});
 
  
  	$("#jplayer_previous").click( function() {
		playListPrev();
		return false;
	});
 
	$("#jplayer_next").click( function() {
		playListNext();
		return false;
	});
 
  function playListConfig( index ) {
        $("#jplayer_playlist_item_"+playItem).removeClass("jplayer_playlist_current");
        $("#jplayer_playlist_item_"+index).addClass("jplayer_playlist_current");
        playItem = index;
       // $("#jquery_jplayer").jPlayer("setFile", myPlayList[playItem].mp3, myPlayList[playItem].ogg);
  }
 
  function playListChange( index ) {
        playListConfig( index );
        $("#jquery_jplayer").jPlayer("play");
         playerPopUp(index);
  }
 
  function playListNext() {
    var index = (playItem+1 < myPlayList.length) ? playItem+1 : 0;
    playListChange( index );
        playerPopUp(index);
  }
  
  function playListPrev() {
    var index = (playItem-1 >= 0) ? playItem-1 : myPlayList.length-1;
    playListChange( index );
        playerPopUp(index); 
  }
});
