function shopInit (carousel) {
	jQuery("#shopModule .jcarousel-clip .dotCounter").children("img").bind('click', function() {
		carousel.scroll(jQuery.jcarousel.intval(jQuery(this).attr("class")));return false;
	});
}
function shopCounter (carousel, item, idx, state) {
	jQuery("#shopModule .jcarousel-clip .dotCounter img").attr("src","wp-content/themes/hyperakt/_img/lightdot.png");
	jQuery("#shopModule .jcarousel-clip .dotCounter img."+idx).attr("src","wp-content/themes/hyperakt/_img/darkdot.png");
}
function scrollCarousel() {jQuery("#shopModule .jcarousel-next").trigger("click");}

function loadsongs() {
	var ms = [];
	
	jQuery.ajax({
		type: "GET",
		url: "wp-content/themes/hyperakt/now_playing.xml",
		dataType: "xml",
		success: function(songinfo) {
			jQuery(songinfo).find('song').each(function() {
				var title = jQuery(this).find('title').text();
				var artist= jQuery(this).find('artist').text();
				var album = jQuery(this).find('album').text();
				var url = jQuery(this).find('urlApple').text();

				ms.push("<div class='songrow'>");
				if(jQuery(this).find('image').text()) {ms.push("<div><img src='"+jQuery(this).find('image').text()+"' /></div>");}
				else {ms.push("<div><img src='wp-content/themes/hyperakt/_img/missingcover.jpg' /></div>");}
				ms.push("<div style='width: 191px'>");
				if(url) {ms.push("<span class='songtitle'><a href="+url+">"+title+"</a></span>");}
				else {ms.push("<span class='songtitle'>"+title+"</span>");}
				if(album) {ms.push("<br /><span class='albumtitle'>"+album+"</span>");}
				if(artist) {ms.push("<br />by "+artist);}
				ms.push("</div><div class='clear'></div></div>");
				
				jQuery("#songs").html(ms.join(""));
			});
		}
	});
}

jQuery(document).ready(function() {
	loadsongs();
	var newsong = setInterval("loadsongs()", 15000);

	if (document.images) {
		imageUrl = new Array(8);
		imageUrl[0] = "wp-content/themes/hyperakt/_img/btn-search-over.gif";
		imageUrl[1] = "wp-content/themes/hyperakt/_img/playtags_bg.png";
		imageUrl[2] = "wp-content/themes/hyperakt/_img/playtags_bottom.png";
		imageUrl[3] = "wp-content/themes/hyperakt/_img/playtags_top.png";
		imageUrl[4] = "wp-content/themes/hyperakt/_img/logos.gif";
		imageUrl[5] = "wp-content/themes/hyperakt/_img/followbg.png";
		imageUrl[6] = "wp-content/themes/hyperakt/_img/popupbg.png";
		imageUrl[7] = "wp-content/themes/hyperakt/_img/sharebg.png";
		for(var n = 0; n <= 7; n++) {
			preloadWorkImgs = new Image();
			preloadWorkImgs.src = imageUrl[n];
		}
	}
	jQuery("#submit").attr("value","");
	jQuery("#submit").hover(function(){jQuery("#submit").css("background-position","0 -35px");},function(){jQuery("#submit").css("background-position","0 0");});
	jQuery("#hyperaktivists .author").hover(
		function(){jQuery(this).children(".navName").css("visibility","visible");},
		function(){jQuery(this).children(".navName").css("visibility","hidden");}
	);
	jQuery("#headerRight form").hover(
		function(){jQuery("#searchsubmit").css("background-image","url(wp-content/themes/hyperakt/_img/btn-search-over.gif)");},
		function(){jQuery("#searchsubmit").css("background-image","url(wp-content/themes/hyperakt/_img/btn-search.gif)");}
	);
	jQuery("#headerRightDetails").mouseleave(function() {jQuery("#catList").hide();jQuery("#catTitle").show();});
	jQuery("#follow").mouseenter(function(){jQuery("#overlay").show();});
	jQuery("#follow").mouseleave(function(){jQuery("#overlay").hide();});
	var autoCaseCarousel = setInterval("scrollCarousel()", 5000);
	jQuery("#shopModule").hover(function(){clearInterval(autoCaseCarousel);},function(){autoCaseCarousel = setInterval("scrollCarousel()", 5000);});
	jQuery("#shopCarousel").jcarousel({scroll:1,animation:500,wrap:'last',initCallback: shopInit,itemFirstInCallback: shopCounter});
});
