var $j = jQuery.noConflict();

$j(document).ready(function() {
	
	var list = $j(".imgContainer");
	var total = $j(".imgContainer").length;
	var count = 0;
	var containerWidth = 0;
	
	$j(".imgContainer").hide();

	loadImage();
	
	function loadImage() {
		
		// Save the path
		var path = $j(list[count]).attr("path");
		
		// Create a new image
		var img = new Image();
		
		// Load the image
		$j(img).load(function() {

			// Add the image to the container
			$j(list[count]).append(this);
	
			$j(this).parent().fadeIn('slow');
			
			$j(this).parent().css("width",$j(this).width());

			var w = $j(this).width();
			
			if (count == (total-1)) {
				$j(this).parent().css("margin-right",0);
				containerWidth += (w+20);
			} else {
				containerWidth += (w+35);
			}
			
			// Set the width of the container
			$j("#scrollContent").css("width",containerWidth);
			
			//$j(window).resize();
			
			count++;
			
			if (count < total) {
				loadImage();
			} else {
				//setTwitter();	
			}

		// Set the new image path
		}).attr('src', path);
	}
	
	var loc = window.location.href;
	var arr = loc.split("/");
	arr.pop();
	loc = arr.join("/");
	
	function setTwitter() {
		jQuery.get(String(loc+"/assets/php/twitter.php"), function(data) {
			$j(".footerBlock.twitter").append(data).slideDown();
			Cufon.refresh();

			setTubmlr();
		});
	}
	
	function setTubmlr() {
		jQuery.get(String(loc+"/assets/php/tumblr.php"), function(data) {
			$j(".footerBlock.tumblr").append(data).slideDown();
			Cufon.refresh();
	
			setLastFM();
		});
	}
	
	function setLastFM() {
		jQuery.get(String(loc+"/assets/php/lastfm.php"), function(data) {
			$j(".footerBlock.lastfm").append(data).slideDown();
			Cufon.refresh();

		});
	}
});
