$(document).ready(function(){

	var noartistrecs = count_sleeves("#noartist");
	var steverecs = count_sleeves("#steve");
	var axwellrecs = count_sleeves("#axwell");
	var sebastianrecs = count_sleeves("#sebastian");
	$("#noartist #knob").draggable({ axis: 'x',containment: 'parent', drag: function(event, ui) { 
			var offset = $("#noartist #knob").position();
			var ox = offset.left;
			$("#noartist #ox").val(ox); 
			move_sleeve(ox,noartistrecs,"#noartist");
		 }
	 });
	 
	$("#steve #knob").draggable({ axis: 'x',containment: 'parent', drag: function(event, ui) { 
			var offset = $("#steve #knob").position();
			var ox = offset.left;
			$("#steve #ox").val(ox); 
			move_sleeve(ox,steverecs,"#steve");
		 }
	 });
	 
	$("#axwell #knob").draggable({ axis: 'x',containment: 'parent', drag: function(event, ui) { 
			var offset = $("#axwell #knob").position();
			var ox = offset.left;
			$("#axwell #ox").val(ox); 
			move_sleeve(ox,axwellrecs,"#axwell");
		 }
	 });
	 
	$("#sebastian #knob").draggable({ axis: 'x',containment: 'parent', drag: function(event, ui) { 
			var offset = $("#sebastian #knob").position();
			var ox = offset.left;
			$("#sebastian #ox").val(ox); 
			move_sleeve(ox,sebastianrecs,"#sebastian");
		 }
	 });
	 
	$("#noartist #records li").click(function(){
		var sleeve;
		sleeve = $(this).attr("id");
		show_video(sleeve,0,"#noartist");
	});
	
	$("#steve #records li").click(function(){
		var sleeve;
		sleeve = $(this).attr("id");
		show_video(sleeve,0,"#steve");
	});
	
	$("#axwell #records li").click(function(){
		var sleeve;
		sleeve = $(this).attr("id");
		show_video(sleeve,0,"#axwell");
	});
	
	$("#sebastian #records li").click(function(){
		var sleeve;
		sleeve = $(this).attr("id");
		show_video(sleeve,0,"#sebastian");
	});
	
	$('#noartist #scrollbar').tinyscrollbar();
	
	$("#artists input").click(function(){
		var artist = $(this).attr("id");
		//var checked = $("input[@id="+artist+"]:checked").length;
		//alert(checked);
		if ($('#artists #'+artist).is(':checked')) {
		//if (checked == 0){
			$("#noartist ."+artist+"_supress").addClass(artist);
			$("#noartist ."+artist+"_supress").removeClass(artist+"_supress");
		} else{
			$("#noartist ."+artist).addClass(artist+"_supress");
			$("#noartist ."+artist).removeClass(artist);
		}
	});

	$(".overview .listitem .emi_buy_button_link img").attr("src","/wp-content/themes/shm/_/images/slider/buy.png");
	$(".overview .listitem .buy-link img").attr("src","/wp-content/themes/shm/_/images/slider/buy.png");
	$(".buybtn").fadeIn();
	Shadowbox.init();
});

function move_sleeve(ox,recs,artistid){
	var slen = 340/recs;
	var sec = Math.round(ox/slen) + 1;
	//alert(artistid+" .rec"+sec);
	show_sleeve(artistid+" .rec"+sec);
}

function show_sleeve(sleeve){
	if($(sleeve).hasClass('up')){
	} else {
		$(".up").animate({ top: "+=200px", left: "+=14px" }, 600 ).removeClass('up');
		$(sleeve).addClass('up');
		$(sleeve).animate({ top: "-=200px", left: "-=14px" }, 900 );
	}
}

function count_sleeves(artistid){
	var ct = 0;
	$(artistid+' #records li').each(function(index) {
		ct++;
	  });
	return ct;
}

function show_video(sleeve,id,artistid){
	var showid = "#" + sleeve + "vid";
	var buyid = "#" + sleeve + "buy";
	var vidcontent = $(showid).val();
	var buycontent = $(buyid).val();
	var title = $(id+" .title").html();
	var buycontent = $(id+" .hidebut").html();
	if (buycontent != ""){
		//var buybut = '<a href="'+ buycontent +'" target="_blank"><img style="float:right;" src="/wp-content/themes/shm/_/images/slider/click-buy.png" alt="Click here to buy" /></a>';
		var buybut = buycontent;
	} else{
		var buybut = "";
	}
	$("#noartist #slider-video").empty();
	$("#steve #slider-video").empty();
	$("#axwell #slider-video").empty();
	$("#sebastian #slider-video").empty();
	$(artistid+" #slider-video").append(vidcontent);
	if (id != 0){
		$(artistid+" .listitem").removeClass("active");
		$(artistid+" "+id).addClass("active");
	} else{
		$(artistid+" .listitem").removeClass("active");
		$(artistid+" li").removeClass("active");
		$(artistid+" #"+sleeve+"list").addClass("active");
		title = $(artistid+" #"+sleeve+"list"+" span").html()
		}
	$(artistid+" #video-title").fadeOut(function(){
		$(artistid+" #video-title").empty();
		$(artistid+" #video-title").append(title);
		$(artistid+" #video-title").fadeIn();
	});
	//return false;
	//alert(vidcontent);
}
