function autoLoad(){
	if ($('#frontpageloader').length){
						setTimeout(function() { $('#frontpageloader').fadeOut('slow',function(){beginLoad()}); }, 2500);
	}else {beginLoad();}
	
	}

function beginLoad(){	
	var max = $("ul#portfolio > li").length;
	var mid = 6;
	
	
	if (max<mid)
	{
		 LoadImage(0,max,max);
	}
	else if(max>0)
	  {	
		  LoadImage(0,mid,max);
	  }
	
	function showLi(index,mid,max){
		if (index<mid){
		var curr = $("li#portfolio_"+index);
		if (curr.length > 0)
			curr.fadeIn(173,function(){showLi(index+1,mid,max);});
		else showLi(index+1,mid,max);
		}else {
			
			LoadImages(mid,max);
			}
	}
	// function of loading image
	// params: (int) index of image in array, (int) length of images array
	
	function LoadImages(mid,max){
		if(mid<max)
				{	// current LI
					var curr = $("li#portfolio_"+mid);
					// new image object
			        var img = new Image();
					// image onload
			        $(img).load(function () {
			            $(curr).removeClass('loading');
						$(curr).find("img.gImage").attr("src",this.src);
						$(curr).fadeIn(173,function(){
								// once the current loaded, trigger the next image
								LoadImages(mid+1,max);
							});
			        }).error(function () {
						// on error remove current
						$(curr).remove();
						// trigger the next image
						LoadImages(mid+1,max);
			        }).attr('src', $(curr).find("a").attr("href"));
				}
		}
	
	function LoadImage(index,mid,max)
		{
			if(index<mid)
				{	// current LI
				
					var curr = $("li#portfolio_"+index);
					
					// new image object
			        var img = new Image();
					
					// image onload
			        $(img).load(function () {
						$(this).css({'display':'none'});
			            curr.removeClass('loading');
						curr.find("img.gImage").attr("src",this.src);
								LoadImage(index+1,mid,max);
			        }).error(function () {
						
						// on error remove current
						$(curr).remove();
						// trigger the next image
						LoadImage(index+1,mid,max);
			        }).attr('src', $(curr).find("a").attr("href"));
					
					
				}else{
					$("ul#portfolio li").each(function(index,value){
							$(this).css('display','none');
					});
						$('#loader').fadeOut('fast',function(){showLi(0,mid,max);});
						
					}
		}
		
}
