$.fn.wait = function(time, type) {
    time = time || 1000;
    type = type || "fx";
    return this.queue(type, function() {
        var self = this;
        setTimeout(function() {
            $(self).dequeue();
        }, time);
    });
};
$(document).ready(function(){
	$.Lightbox.construct({
		show_linkback: false,
		show_info: true,
		show_extended_info: false,
		download_link: false
	});
	$.getJSON("images/sets/sets.json", function(data){
		$.each(data.sets, function(i,set){
			var headImg;
			
			$.each(set.images, function(k,image) {
				if(k == 0) {
					headImg = '<img src="' + data.setsdirectory + "/" + set.directory + "/" + image.filename + '" />';
				} else if(k == 1) {
					$('<div class="lbheaderimg"><a href="' + data.setsdirectory + "/" + set.directory + "/" + image.filename + '" rel="lightbox-' + set.name + '">' + headImg + '</a></div>').appendTo("#topimagebox").children().attr("title", set.name);
					/*
.mouseup(function(){
						console.log("mousedown");
						$(this).attr("title", $(this).data("name") + " ");
					}).mouseout(function(){
						console.log("mouseout");
 						$(this).removeAttr("title");
					});
*/
				}
				else {
					$("<a href='" + data.setsdirectory + "/" + set.directory + "/" + image.filename + "' rel='lightbox-" + set.name + "'>&nbsp;</a>").attr("title", image.name + " ").appendTo("#maskedlinks");
				}
			});
			$(".lbheaderimg > a[rel='lightbox-" + set.name + "'], #maskedlinks > a[rel='lightbox-" + set.name + "']").lightbox();
		});
		$("#topimagebox").width(data.sets.length*320);
		CSBfleXcroll('topmask');
		// News
		$.get("news.html", function(data) {
			$("#sidecopy").append(data);
			CSBfleXcroll('sidecopy');
		}, "html");
		
	});
	
	location.href = "#ia";
});
