	var blanks = Array()	
	var i = 0
	var thisid = 0

	$('#flickr div.loadable-photo').css('opacity',0.6)
	
	$('#flickr div.loadable-photo').hover( function() {
		$(this).append('<span class="mag">')
		$(this).css('opacity',1)
		
	}, function() {
			$(this).children('span').remove()
		$(this).css('opacity',0.6)
		
	} )

	function getBlanks() {
		divscount = ($('#flickr > div.photo').size())
		divscount = parseInt(divscount)
		lastdiv = ($('#flickr div.photo:last').attr('id'))
		lastdiv = lastdiv.substr(1)
		lastdiv = parseInt(lastdiv)
		string = ''
		blanks =Array()
	
		
			for(i=0; i<=(lastdiv); i++) {
				if (i < 10) {
				string = '0'+i
			 	} else {
				string = i+''
				}
							
				if ($('#p'+string).length == 0) {
					blanks.push(string)
				}
	
			}
	}
	getBlanks()
	
	function zeroPad(num, numZeros) {
	        var n = Math.abs(num);
	        var zeros = Math.max(0, numZeros - Math.floor(n).toString().length );
	        var zeroString = Math.pow(10,zeros).toString().substr(1);
	        if( num < 0 ) {
	                zeroString = '-' + zeroString;
	        }

	        return zeroString+n;
	}
	

	function crawl() {
	
	if (notworkOn && ($('#imgLg').css('display') != 'block')) {

	var targetid = 0
	var targetRow = 0
	var targetCol = 0
	var signage = ''
	var direction = ''
	var parts = ''
	
	found = false
	randkey = Math.floor ( Math.random() * blanks.length );
	 
	targetid = blanks[randkey];
	targetid = targetid+''
	if (targetid.length == 1){
		targetid= '0'+targetid
	}

	var parts = targetid
	parts = parts+''
	
	if (parts.length < 2) {
		parts='0'+parts
	}
	targetRow = parts.substring(0,1)
	targetCol = parts.substring(1)
	

	targetRow = parseInt(targetRow)
	targetCol = parseInt(targetCol)

	// Dir (direction) equals random number between 0 and 3
	k=0
	while (!found) {
	k++	
		fromCol = targetCol
		fromRow = targetRow
		newCol= fromCol
		newRow= fromRow
		
	
		
		var dir =Math.floor(Math.random()*4)
		if (dir == 0) {
			
			
			// Move left
			fromCol++
			if ($('#p'+fromRow+fromCol).length != 0) {
				//	alert('left!')
				found = true
				$('#p'+fromRow+fromCol).animate({ 'left': '-=75' })
					$('#p'+fromRow+fromCol).attr('id', 'p'+fromRow+newCol)
			} 
		} else if (dir == 1) {
			
			// Move up
			fromRow++
			if ($('#p'+fromRow+fromCol).length != 0) {
				//	alert('up!')
				found = true
					$('#p'+fromRow+fromCol).animate({ 'top': '-=75' })
						$('#p'+fromRow+fromCol).attr('id', 'p'+newRow+fromCol)
			}
			
				
		} else if (dir == 2) {
			
			
			// Move down
		
			fromRow--
			if ($('#p'+fromRow+fromCol).length != 0) {
				
				//	alert('down!')
				found = true
					$('#p'+fromRow+fromCol).animate({ 'top': '+=75' })
					$('#p'+fromRow+fromCol).attr('id', 'p'+newRow+fromCol)
			}
			
		} else {
			
			 //Move right
			fromCol--
			if ($('#p'+fromRow+fromCol).length != 0) {
			//		alert('right!')
				found = true
				$('#p'+fromRow+fromCol).animate({ 'left': '+=75' })
				$('#p'+fromRow+fromCol).attr('id', 'p'+fromRow+newCol)
				
			}
			
		}
		if (k >20) {
			found = true
		}
		
		getBlanks()
		
		
	}

} 
	setTimeout ( "crawl()", 5000 );	
}	
	crawl()
	
	$('#flickr div a').click( function() {
		$('#imgLg div.wrapper div.inner2').html('<img class="loading" src="img/icons/loading.gif"/>');
		var imageSrc = $(this).attr('href')
		var caption =  $(this).attr('title')
		var imgid = $(this).parent('div').attr('title')
		
	    img = new Image();
	    $(img).hide();
		$(img).load(function() {
		
	        $('#imgLg div.wrapper div.inner2').html(this);
			
	        $(this).css('display','inline');
		    var width = $(this).width()
		 	$('#imgLg div.wrapper div.inner2').append('<div class="imgTitle" style="width: '+width+'px">'+caption+' &nbsp;&nbsp;<a href="http://www.flickr.com/photos/30162289@N03/'+imgid+'">Flickr</a></div>')
		
		
	    })
	    $(img).attr('src', imageSrc)
		$(img).fadeIn(600)
		
		
		
		
		$('#imgLg').fadeIn(200)
		return false
	})
	
	
	$('#imgLg').click( function() {
		$('#imgLg').fadeOut(200)
	})


