var Popup = null 
function playerPopUp(index){
//if(Popup!=null){
//}else{
//Popup = window.open("player.php?index1="+index,"playerPop","width=0,height=0,menubar=no,resizable=no,location=no,status=no,titlebar=no") 
//}
}

$(document).ready(function(){

	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"}	];
 
	// Local copy of jQuery selectors, for performance.
	var jpPlayTime = $("#jplayer_play_time");
	var jpTotalTime = $("#jplayer_total_time");
	//var jpStatus = $("#demo_status"); // For displaying information about jPlayer's status in the demo page
 
 	$("#jquery_jplayer").jPlayer({
   // volume:  0,
		ready: function() {
			displayPlayList();
			playListInit(false); // Parameter is a boolean for autoplay.
			//demoInstanceInfo(this.element, $("#demo_info")); // This displays information about jPlayer's configuration in the demo page
		},
		oggSupport: false
	})
	.jPlayer("onProgressChange", function(loadPercent, playedPercentRelative, playedPercentAbsolute, playedTime, totalTime) {
		jpPlayTime.text($.jPlayer.convertTime(playedTime));
		jpTotalTime.text($.jPlayer.convertTime(totalTime));
 
		//demoStatusInfo(this.element, jpStatus); // This displays information about jPlayer's status in the demo page
	})
	.jPlayer("onSoundComplete", function() {
		playListNext();
        opener.document.playListNext();
	});
 
	$("#jplayer_previous").click( function() {
		playListPrev();
        opener.document.playListPrev();
		return false;
	});
 
	$("#jplayer_next").click( function() {
		playListNext();
        opener.document.playListNext();
		return 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 );
		}
     
	}
 
	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); 
        	
	}
});
