var lookbook = {
	images: [],
	imagesWidth: 707,
	imagesSpacing: 7,
	containerWidth: 850,
	totalWidth: 0,
	lastMouseX: 0,
	mouseMoving: false,
	scrollerWidth: 48,
	totalScroll: 0,
	scrollAmount: 0,
	loadedImages: [],
	
	init: function(root){
		
		$.ajax({
			type: "POST",
			url: root + "lib/ajax.class.php",
			beforeSend: function(){
				$("div#lookbook").html("<img src=\"" + root + "html/img/loading.gif\" style=\"margin-top:215px;margin-left:400px\">");
			},
			success: function(data, status){
				data = $.evalJSON(data);
				
				lookbook.images = data.images;
				
				var img = "";
				var total_width = 0;
				var content = "";
				
				for(var i = 0; i < lookbook.images.length; ++i){
					lookbook.loadedImages.push(new Image());
					lookbook.loadedImages[lookbook.loadedImages.length - 1].src = lookbook.images[i];
				}
				
				loadedImages = 0;
				
				$.each(lookbook.loadedImages, function(index, value){
					$(value).load(function(){
						content = content + '<div class="item"><img class="image" src="' + value.src + '" alt="" /></div>';
						loadedImages++;
						
						
						if(loadedImages == lookbook.loadedImages.length ){
							lookbook.display(content);
						}
					});
				});

			}
		});
		
		
	},
	
	display: function(content){
		$("div#lookbook").html(content);
		
		var width = 0;
		var length = 0;
		if($.browser.msie){
			var item = document.getElementsByClassName("image");
			for(var i = 0; i < item.length; ++i){
				width += parseInt(item[i].width, 10);
				length++;
			}
		}else{
			$("div.item").each(function(){
				width += parseInt($(this).css("width"), 10);
			});
			
			length = $("div.item").length;
		}
		
		$("div#lookbook").css("width", (width) + (length * 10));
		$("div#lookbook-scroll").slider({
			animate: false,
			max: ((width) + (length * 10)) - parseInt($("div#lookbook-container").css("width"), 10), 
			slide: function(e, ui) {
				$("div#lookbook").css("left", "-" + ui.value + "px");
			}
		});
	}
	
};

document.getElementsByClassName = function(cl) {
	var retnode = [];
	var myclass = new RegExp('\\b'+cl+'\\b');
	var elem = this.getElementsByTagName('*');
	for(var i = 0; i < elem.length; i++){
		var classes = elem[i].className;
		if(myclass.test(classes)){
			retnode.push(elem[i]);
		}
	}
	return retnode;
}; 