$(document).ready(function() {


if ($("slide-controller")) {
		$("#slide-controller").jFlow( {
			slides : "#slidercontent",
			controller : ".slidenum-off", // must be class, use . sign
			slideWrapper : "#jFlowSlide", // must be id, use # sign
			selectedWrapper : "slidenum-on", // just pure text, no sign
			auto : true, // auto change slide, default true
			width : "780px",
			height : "220px",
			duration : 600,
			prev : ".jFlowPrev", // must be class, use . sign
			next : ".jFlowNext", // must be class, use . sign
			auto : true,
			desc : ".slide-desc",
			descCont : "#slide_desc"
		});
	}


$jScroller.add("#jtrack","#jtrackname","left",1);
$jScroller.start();



$("a.thumb-show").each(function() {

	
	$(this).qtip({
	  content: {
		text:'<img src="ref/big/'+$(this).attr("rel")+'" alt="" />',
		title: {
			text:$(this).attr("title")
		}
	},
	  
	  position: {
		   corner: {
			  target: 'middleLeft',
			  tooltip: 'rightBottom'
		   }
		},
	  style:{
		  name:'dark',
		  padding:4,
		  width:410,
	  	  tip: true,
		  border: { width: 2, radius: 6 }
		  
	  }
});

});


	$('#jtrack').hover(
			function () {
				$("#jplayertools").fadeIn();
			},
			function () {
				
			}
	);
	
	$("#jplayertools").hover(
			function () {
				
			},
			function () {
				$(this).fadeOut();
			}
	);


	
	var playItem = randomIndex(0,2);
	var myPlayList = [
	                  {name:"Ink OST - John's Walk",mp3:"http://www.projepi.com/v1/music/Ink_Johns-Walk.mp3"},
	                  {name:"Miaow - Bubble",mp3:"http://www.projepi.com/v1/music/Miaow_Bubble.mp3"},
	                  {name:"Tappy - The Best Is Yet To Come",mp3:"http://www.projepi.com/v1/music/mgs.mp3"}
	                  ];
	
	 $("#jplayer2").jPlayer({
			ready: function () {
		 		playListInit(true);
			}
		})
		.jPlayerId("play", "jplay")
		.jPlayerId("pause", "jpause")
		.jPlayerId("stop", "jstop")
		.jPlayerId("volumeMin", "jmute")
		.jPlayerId("volumeMax", "jfull")
		.jPlayerId("volumeBar", "jhalf")
		.jPlayerId("loadBar", "jloadbar")
		.jPlayerId("playBar", "jprogress")
		.onProgressChange( function(lp,ppr,ppa,pt,tt) {
	 		$("#jpcent").text(parseInt(ppa)+"%");
		})
		.onSoundComplete( function() {
			playListNext();
		});
	 	
		function randomIndex(minVal,maxVal,floatVal) {
		   var randVal = minVal+(Math.random()*(maxVal-minVal));
		   return typeof floatVal=='undefined'?Math.round(randVal):randVal.toFixed(floatVal);
		}
		 
		$("#j-prev").click( function() {
				playListPrev();
				return false;
			});

		$("#j-next").click( function() {
				playListNext();
				return false;
		});
 
		 
	 	function playListInit(autoplay) {
			if(autoplay) {
				playListChange( playItem );
			} else {
				playListConfig( playItem );
			}
		}
	 	function playListConfig( index ) {
			playItem = index;
			$("#jplayer2").setFile(myPlayList[playItem].mp3);
		}

		function playListChange( index ) {
			playListConfig( index );
			$("#jtrackname").text(myPlayList[index].name);
			$("#jplayer2").play();
		}

		function playListNext() {
			var index = (playItem+1 < myPlayList.length) ? playItem+1 : 0;
			playListChange( index );
		}

		function playListPrev() {
			var index = (playItem-1 >= 0) ? playItem-1 : myPlayList.length-1;
			playListChange( index );
		}





});