/*  Wexcode Javascript
    --------------------------------------------------------------
    Coded by: Wex ( http://www.wexcode.com/ )
*/

$(function() {
	$("#small").accessNews();	
	$(".javascript_css").css("display", "none");
	
	// http://blueonionsoftware.com/blog.aspx?p=4f47563f-69c4-4483-9a98-8c6a425fcf2c
	$.fn.delay = function(time, callback)
	{
	    return this.animate({ opacity: '+=0' }, time, callback);
	}	
	
	/* Switch to large and back */
	$.fn.swapImage = function(){
		var name = $(this).attr("src");
		name = name.substr(0, name.length - 10);
		var image = "img[src='" + name + "_big.gif']";
		var width = $(image).width();
		var height = $(image).height();
		$("#small").css("display", "none");
		$(image).css({visibility: "visible"}).parent().parent().css({visibility: "visible"});
		$("#big").animate({padding: "12px", height: height, width: width});
		newWidth = width + 101 + "px";
		newHeight = height + 12 + "px";
		$("#content").animate({width: newWidth});
		$("#container").animate({width: newWidth});
		return image;
	};
	
	$("#small li a img").click(function() {
		var image = $(this).swapImage();
		$(image).click(function() {
			// Finish the animation first...
			if(!$("#small").is(":animated")) {
				$("#content").animate({width: "635px"});
				$("#container").animate({width: "712px"});
				$("#big").animate({padding: "0px", height: "0px", width: "0px"});
				$("#small").fadeIn();
				$(image).css({visibility: "hidden"}).parent().parent().css({visibility: "hidden"});
			}
			return false;
		});
		return false;
	});
	
	/* Switch to thumbnails and back */
	$.fn.switchThumbs = function(){
		$("#small").delay(0).toggle("slow");
		$("#thumbnails").delay(0).toggle("slow");
	};
	$(".view-all a, .view-less a").click(function() {
		// Make sure that a double click doesn't have any effect
		if(!$("#small, #thumbnails").is(":animated")) {
			$(this).switchThumbs();
			var page = $(".view-all").attr("id");
			page = page.substr(page.length-1, 1);
			$("#thumbnails li:eq("+page+")").toggleClass("current");
		}
		return false;
	});
	
});