$(document).ready(function(){	

	// Slide main content tabs
	$("#tabbed a").click(function(){
		$("#tabbed a.selected").removeClass("selected");
		var index = $("#tabbed a").index(this);
		$(this).addClass("selected");
		$("div#slider").stop().animate({ marginLeft: -495*index }, {queue:false,duration:500});
		return false;
	});
	
	// Slide large images on thumbnail click
	$("#thumbnails a").click(function(){
		var index = $("#thumbnails a").index(this);
		$("div#large_images").stop().animate({ marginLeft: -495*index }, {queue:false,duration:500}); 
		return false;
	});
	
	// Slide through thumbnails, 3 at a time
	var total_images = $("#thumbnails a").size();
	var total_rotations = parseInt(total_images/3) - 1;
	var current_rotation = 0;
	
	if (total_images % 3 != 0) { total_rotations += 1; }
	
	$("#slide_right").click(function(){
		if (current_rotation < total_rotations)
		{	
			current_rotation++;
			$("#thumbnails").stop().animate({ marginLeft: -396*current_rotation }, {queue:false,duration:500}); 
		}
		return false;
	});
	
	$("#slide_left").click(function(){
		if (current_rotation >= 1)
		{
			current_rotation--;
			$("#thumbnails").stop().animate({ marginLeft: -396*current_rotation }, {queue:false,duration:500}); 
		}
		return false;
	});
	
	// AJAX calls to keeping getting subfolders when clicking on folders in the resource centre
	
	// actions for sidebar toplevel folders
	$("#resources_nav a").live("click", function(){
		if(!$(this).hasClass("clicked"))
		{
			$("#resources_nav a.clicked").removeClass("clicked");
			$(this).addClass("clicked");
			this_obj = $(this);
			$.post("http://www.wowtoys.com/wp-content/themes/wowpress/php/print_dir.php", { path: this_obj.attr("href") }, function(data){ if (data.length>0) $("#resources_content").html(data); }, "html");
		}
		return false;
	});
	
	// actions for main content area folders
	$("#resources_content a.folder").live("click", function(){
		if(!$(this).hasClass("clicked"))
		{
			$(this).addClass("clicked");
			this_obj = $(this);
			$.post("http://www.wowtoys.com/wp-content/themes/wowpress/php/print_dir.php", { path: this_obj.attr("href") }, function(data){ if (data.length>0) this_obj.after(data); }, "html");
		}
		else
		{
			// if the folder is already open, unclick it and remove subfolders holder
			$(this).next().remove();
			$(this).removeClass("clicked");
		}
		return false;

	});
		
});
