function zeroPad(num,count)
{
var numZeropad = num + '';
while(numZeropad.length < count) {
numZeropad = "0" + numZeropad;
}
return numZeropad;
}



Event.observe(window, 'load', function () {
 	
	if ($('gal')!=null) {
		Event.observe('balful', 'mouseover', function  () {
		pos= parseInt($('gal').style.left);
		if (0>pos || 1) {
		//new Effect.Opacity('balful', {  to: 0.9, duration: 0.5 });
		
		}
	});

	Event.observe('jobbful', 'mouseover', function  () {
		width= parseInt($('gal').style.width);
		pos= parseInt($('gal').style.left);
		if (isNaN(pos)) pos=0;
		if (pos>=-1*width || 1) {
		//new Effect.Opacity('jobbful', { to: 0.9, duration: 0.5 });
		
		}
	});	

	Event.observe('balful', 'mouseout', function  () {
		//new Effect.Opacity('balful', {  to: 0.5, duration: 1 });
		
	});
	
	Event.observe('jobbful', 'mouseout', function  () {
		//new Effect.Opacity('jobbful', { to: 0.5, duration: 1 });
		
	});	
	
	req = new Ajax.Request('/getfiles.php', {
		method: 'get',
		parameters:{
			path: document.location
		},
		onSuccess: function  (transport,json) {
			a=parseInt(document.location.toString().substring(document.location.toString().lastIndexOf('/')+1));
			if(typeof(a)!="number"){
				a=0;
			}
			
			$('akep').style.backgroundImage="url("+json[a].path+")";
			
			$('akep').style.width=json[a].width+"px";
			if(typeof(json[a].left1)!="undefined"){
				/*$('elso').style.left=json[a].left1+"px";
				$('elso').style.top=json[a].top1+"px";
				$('elso').href=json[a].link1;
				$('elso').style.display='block';
				$('masodik').style.left=json[a].left2+"px";
				$('masodik').style.top=json[a].top2+"px";
				$('masodik').href=json[a].link2;
				$('masodik').style.display='block';
				$('harmadik').style.left=json[a].left3+"px";
				$('harmadik').style.top=json[a].top3+"px";			
				$('harmadik').href=json[a].link3;
				$('harmadik').style.display='block';*/
			}else{
				/*$('elso').style.display='none';
				$('masodik').style.display='none';
				$('harmadik').style.display='none';*/
			}
			$('all').innerHTML=json.length;
			$('curr').innerHTML=a+1;
			if (json.length==a+1) $('jobbful').style.display='none';
			if (a==0) $('balful').style.display='none';
			
			
			Event.observe('jobbful', 'click',function  () {
				
				if (json.length>a+1) {
					a+=1;
					$('balful').style.display='block';
					new Effect.Opacity('akep', { to: 0.0, duration: 0.5, 
					afterFinish:function(){
										
						$('akep').style.backgroundImage="url("+json[a].path+")";
						$('akep').style.width=json[a].width+"px";
						if(typeof(json[a].left1)!="undefined"){
						/*$('elso').style.left=json[a].left1+"px";
						$('elso').style.top=json[a].top1+"px";
						$('elso').href=json[a].link1;
						$('elso').style.display='block';
						$('masodik').style.left=json[a].left2+"px";
						$('masodik').style.top=json[a].top2+"px";
						$('masodik').href=json[a].link2;
						$('masodik').style.display='block';
						$('harmadik').style.left=json[a].left3+"px";
						$('harmadik').style.top=json[a].top3+"px";			
						$('harmadik').href=json[a].link3;
						$('harmadik').style.display='block';*/
						}else{
						/*$('elso').style.display='none';
						$('masodik').style.display='none';
						$('harmadik').style.display='none';*/
						}
						new Effect.Opacity('akep', { to: 1.0, duration: 0.5 });
					}
					});
				}
				if(a+1==json.length) $('jobbful').style.display='none';
				$('curr').innerHTML=a+1;
			});			
			
			Event.observe('balful', 'click',function  () {
				
				if (0<a) {
					a-=1;
					$('jobbful').style.display='block';
					new Effect.Opacity('akep', { to: 0.0, duration: 0.5, 
					afterFinish:function(){
						
						$('akep').style.backgroundImage="url("+json[a].path+")";
						$('akep').style.width=json[a].width+"px";
						if(typeof(json[a].left1)!="undefined"){
						/*$('elso').style.left=json[a].left1+"px";
						$('elso').style.top=json[a].top1+"px";
						$('elso').href=json[a].link1;
						$('elso').style.display='block';
						$('masodik').style.left=json[a].left2+"px";
						$('masodik').style.top=json[a].top2+"px";
						$('masodik').href=json[a].link2;
						$('masodik').style.display='block';
						$('harmadik').style.left=json[a].left3+"px";
						$('harmadik').style.top=json[a].top3+"px";			
						$('harmadik').href=json[a].link3;
						$('harmadik').style.display='block';*/
						}else{
						/*$('elso').style.display='none';
						$('masodik').style.display='none';
						$('harmadik').style.display='none';*/
						}
						new Effect.Opacity('akep', { to: 1.0, duration: 0.5 });
					}
					});
				}
				if(a==0) $('balful').style.display='none'
				$('curr').innerHTML=a+1;
			});			
		}
		});
}
});
