// JavaScript Document
function initGalleryImage(pos,big_src){
	var img=todo.get('object_gallery').getElementsByTagName('img')[pos];
	img.style.cursor='pointer';
	img._big_src=big_src;
	img.onclick=function(){
		if(this._timer)return;
		var b=todo.get('object_gallery_big');
		this._tmp=new Image;
		this._tmp.src='image.php?&src='+this._big_src+'&w='+b.width+'&h='+b.height+'&wm=1';
		if(!this._tmp.complete) todo.opacity(todo.get('object_gallery_big'),0.5);
		this._timer=window.setInterval(function(img){return function(){
			if(img._tmp.complete || img._counter>1000){
				b.src=img._tmp.src;
				b.parentNode.href=img._big_src;
				todo.opacity(b,1,50);
				window.clearInterval(img._timer);
				todo.get('announce').innerHTML = img.alt;
				img._timer=null;
			}else img._counter++;
		}}(this),200);
	}
};

$(function(){
	var interval = 5;
	var a;
	var active = true;

	function gallery(){
		if(a=='l')$('#blockgallery').scrollLeft($('#blockgallery').scrollLeft() + 13);
		if(a=='r')$('#blockgallery').scrollLeft($('#blockgallery').scrollLeft() - 13);
		
		if(($('#blockgallery').scrollLeft()%135 < 130 && a=='l') || 
			($('#blockgallery').scrollLeft()%135 > 5 && a=='r')){
			setTimeout(function(){gallery()},40);
		}else{
			$('#blockgallery').scrollLeft(Math.round($('#blockgallery').scrollLeft()/135)*135);
			active = true;
		}
	}

	$('#blockimgright').click(function(){
		if(active == true && ($('#blockgallery').scrollLeft() <= (($('#blockgallery ul li img').get().length)/2).toFixed()*135-135*4)){
			active = false;
			a = 'l';
			gallery();
		}
	});
	$('#blockimgleft').click(function(){
		if(active == true && $('#blockgallery').scrollLeft() != 0){
			active = false;
			a = 'r';
			gallery();
		}
	});
});
