$(document).ready(function(){
	$(window).load(function(){
			
		$.getJSON("/itunes/preview.json",null,itunes_load);
					
		function itunes_load(json){
			
			var count = 0;
			$.each(json,function(i){
				count = i;
			});
			var total = count + 1;
			
			var total_div = total/3;
						
			var x = 1;
			var a = 0;
			var b = 1;
			var c = 2;
			while(x <= total_div){
				if(x <= 1){
					$("div#itunes1").html('<a href="' + json[a].Itune.link + '"><img src="/img/itunes/' + json[a].Itune.button + '" /></a>');				
					$("div#itunes2").html('<a href="' + json[b].Itune.link + '"><img src="/img/itunes/' + json[b].Itune.button + '" /></a>');
					$("div#itunes3").html('<a href="' + json[c].Itune.link + '"><img src="/img/itunes/' + json[c].Itune.button + '" /></a>');
				} else {
					$("div#itunes1").append('<a href="' + json[a].Itune.link + '"><img src="/img/itunes/' + json[a].Itune.button + '" /></a>');
					$("div#itunes2").append('<a href="' + json[b].Itune.link + '"><img src="/img/itunes/' + json[b].Itune.button + '" /></a>');
					$("div#itunes3").append('<a href="' + json[c].Itune.link + '"><img src="/img/itunes/' + json[c].Itune.button + '" /></a>');
				}
				

				a += 3;
				b += 3;
				c += 3;
				x += 1;
			}
			
			
			$('div#itunes1').cycle({
				speed: 1500,
				timeout: 7000,
				delay: 0,
				pause: 1,
				fit: 1
			});

			$('div#itunes2').cycle({
					speed: 1500,
					timeout: 7000,
					delay: 2500,
					pause: 1,
					fit: 1
				});	
				
			$('div#itunes3').cycle({
					speed: 1500,
					timeout: 7000,
					delay: 5000,
					pause: 1
			});
		
		}
	});
});