var prev,next,current,noloader,totalheight,totalwidth,delay,picsgray,pics,ready;

current=0;
ready=0;
go=0;
noloader=0;

function action(go){
	if(go=='left')current==0?current=pics.length-1:current--;
	else if (go=='right')current==pics.length-1?current=0:current++;
	current==0?prev=pics.length-1:prev=current-1;
	current==pics.length-1?next=0:next=current+1;
	go==0?redraw():loader();
}

function redraw(){
//alert(widths[current]);
	margin=totalwidth-widths[current];
	leftmargin=Math.floor(margin/2);
	rightmargin=Math.ceil(margin/2);

	document.getElementById("loader").style.visibility='hidden';


//ERROR

	
	document.getElementById("gleft").style.backgroundImage='url('+picsgray[prev]+')';	
	document.getElementById("gleft").style.width=leftmargin+'px';

	document.getElementById("gright").style.backgroundImage='url('+picsgray[next]+')';	
	document.getElementById("gright").style.width=rightmargin+'px';	
	
	document.getElementById("gmain").style.width=widths[current]+'px';

//ERROR

	document.getElementById("gmainimg").innerHTML='<img src="'+pics[current]+'" height="'+totalheight+'" width="'+widths[current]+'" />';	
	document.getElementById("dyn").innerHTML=descriptions[current];
//	document.getElementById("dyn").innerHTML='foo';
}

function picloaded(){
	if(ready==2){
		ready=0;
		window.setTimeout("redraw()", delay);
	}
	else ready++;
}

function loader(){
	document.getElementById("loader").style.visibility='visible';
	if(noloader)window.setTimeout("redraw()", delay);
	else {
		document.getElementById("preload").innerHTML='<img src="'+pics[current]+'" onload="picloaded();" /><img src="'+picsgray[next]+'" onload="picloaded();" /><img src="'+picsgray[prev]+'" onload="picloaded();" />';
	}
}

/*
if(navigator.userAgent.indexOf('Opera')&&navigator.appVersion.indexOf('Macintosh') != -1){
	alert('foo');
	noloader=1
	window.setTimeout("redraw()", delay);
}
*/
