use( "thing.slide" );
function Photographer( name, gear, path, imgSrc ){
	this.name = name;
	this.gear = gear;
	this.path = path;
	this.img = new Image();
	this.img.src = imgSrc;
	this.index = Photographer.all.length;
	Photographer.all[ this.index ] = this;
}
Photographer.all = new Array();
Photographer.prototype.toHtml = function(){
	return ''
		+ '<div id="photo' + this.index + 'Div" class="photoDiv" onmouseover="bringToFront(this);" style="border:1px solid #4A4B3A;left:' + this.x + ';top:' + this.y + ';">'
		+ '<img src="' + this.img.src + '" alt="' + this.name + '" onmouseover="showPhotographerInfo(this.parentNode,true)" onmouseout="showPhotographerInfo(this.parentNode,false)" onclick="gotoPhotographer(this.parentNode)">'
		+ '</div>'
}
Photographer.writeAll = function() {
	Photographer.shuffle();
	Photographer.placeAll();
	for( var i=0; i<this.all.length; i++ ){
		document.write( this.all[i].toHtml() );	
	}
}


Photographer.shuffle = function(){
	var newAll = new Array();
	for( i=0; i<this.all.length; i++ ){
		var newIndex = Math.floor( Math.random() * this.all.length );
		while( newAll[newIndex] != null ){
			newIndex = (newIndex + 1) % this.all.length;
		}
		newAll[newIndex] = this.all[i];
		newAll[newIndex].index = newIndex;
	}
	this.all = newAll;
}
function makeHoles(){
	var holes = new Array(4);
	var takenHoles = new Array();
	holes[0] = Math.floor(Math.random() * 3) + 1;
	takenHoles[holes[0]] = true;
	for( i=1; i<holes.length; i++ ){
		var hole = Math.floor(Math.random() * 4);
		while( takenHoles[hole] != null ){
			hole = ++hole % 4;
		}
		holes[i] = hole;
		takenHoles[hole] = true;
	}
	return holes;
}
function readCols(){
	var holes = makeHoles();
	var cols = new Array(4);
	for( i=0; i<cols.length; i++ ){
		cols[i] = new Array();
	}
	for( var i=0; i<Photographer.all.length; i++ ){
		var cn = i % 4;
		if( Photographer.all.length - i < 4 ){
			var min = 100;
			var mincn = 0;
			for( j=0; j<cols.length; j++ ){
				if( cols[j].length < min ){
					min = cols[j].length; 
					mincn = j;
				}
			}
			cn = mincn;
		}
		var col = cols[cn];
		if( col.length % 4 == holes[cn] ){
			col[col.length] = 0;
		}
		
		col[ col.length ] = Photographer.all[i];
	}
	return cols;
}
Photographer.placeAll = function(){
	var cols = readCols();
	
	var maxY = 0;
	for( var cn=0; cn<cols.length; cn++ ){
		var col = cols[cn];
		var x = cn * 133;
		var y = 0;
		for( var i=0; i<col.length; i++ ){
			if( col[i] ){
				y += Math.floor(Math.random()*3) * 10;
				col[i].x = x;
				col[i].y = y;
				y += 135;
			}
			else if( i==-1 ){
				y += 50;
			}
			else{
				y += 100;
			}
		}
		if( y > maxY ){
			maxY = y;
		}
	}
	document.images.stickImg.height = maxY + 10;
}

function showPhotographerInfo(div, on){
	div.style.border = (on) ? '1px solid white' : '1px solid #4A4B3A'	
	var index = div.id.substring( "photo".length, div.id.length-3 );
	var photographer = Photographer.all[ index ];
	
	nameDiv = document.getElementById('photographerNameDiv');
	gearDiv = document.getElementById('photographerInfoDiv');
	if(photographer && on){		
		nameDiv.innerHTML = photographer.name;
		gearDiv.innerHTML = ( photographer.gear != '' ) ? "Lowepro gear:<br>" + photographer.gear : '' ;
	}
	else{
		nameDiv.innerHTML = "";
		gearDiv.innerHTML = "";
	}
}
function gotoPhotographer( div ){
	var index = div.id.substring( "photo".length, div.id.length-3 );
	var photographer = Photographer.all[ index ];
	location.href = photographer.path;	
}
var gzIndex = 99;
function bringToFront( div ){
	div.style.zIndex = ++gzIndex;
}




