var lis = new Array($('#plThs img').length);

$('#plThs img').each(function(i){
  lis[i] = this; 
});

$('#plThs').html('<div id="th0"><\/div><div id="th1"><\/div><div id="th2"><\/div><div id="th3"><\/div>');

var cols = new Array();
var cola =new Array(4);
var a=0;

for(var i=0;i<lis.length;i++){
	cola[a]=lis[i];
	a++;		
	if(a==4) { 
		var t = new Array(cola[0],cola[1],cola[2],cola[3]);
		cols.push(t); 
		for(var a=0;a<cola.length;a++){
			cola[a]=null;
		}
		a=0;		
	 }	
}
if(a>0)
cols.push(new Array(cola[0],cola[1],cola[2],cola[3]));


var current=0;

$('#plPrev').click(function(){plPrev_click();});
$('#plNext').click(function(){plNext_click();});
Show();

function Show(){
	for(var i=0;i<cols[current].length;i++){
		$('#th'+i).html('');
		if(cols[current][i]!=null)
		$('#th'+i).html('<img src="'+cols[current][i].src+'" alt="'+cols[current][i].alt+'" width="135" onclick="Show_Med(this)" style="cursor:pointer" />');
	}
	$('#plMed').html('<a href="/large.asp?id='+cols[current][0].alt.substr(cols[current][0].alt.lastIndexOf("# ")+2)+'"><img src="'+cols[current][0].src.replace('/th_','/')+'" alt="'+cols[current][0].alt+'" /></a>');
	$('#plTitle').html(cols[current][0].alt);
	
	
	if(current>0) $('#plPrev').css('display','block');
	else $('#plPrev').css('display','none');
	
	if(current<cols.length-1) $('#plNext').css('display','block');
	else $('#plNext').css('display','none');
}

function Show_Med(img){
	$('#plMed').html('<a href="/large.asp?id='+img.alt.substr(img.alt.lastIndexOf("# ")+2)+'"><img src="'+img.src.replace('/th_','/')+'" alt="'+img.alt+'" /></a>');
	$('#plTitle').html(img.alt);
}

function plPrev_click(){
	if(current>0) current--;
	Show();
}

function plNext_click(){
	if(current<cols.length-1) current++;
	Show();
}
