function sliderGallery(){
 this.gall1 = $('#gall1');
 this.gall2 = $('#gall2');
 if (this.gall1.length ==0 || this.gall2.length==0) {return null;}
 var scrl = parseInt((Math.random() * this.gall1[0].clientHeight)/146.667)*146;
 this.gall1.animate({scrollTop:scrl+'px'}, 1);
 //scrl = parseInt((Math.random() * this.gall2[0].clientHeight)/146.667)*146;
 //this.gall2.animate({scrollTop:scrl+'px'}, 1);
 setTimeout("gallery1()", 6200);
 //setTimeout("gallery2()", 6000);
 this.images = Array();
 this.images['.gall2'] = this.gall2.children('table').children('tbody').children('tr').children('td').children('div').children('a').children('img');
 this.gall2.html('<div class="gall2 img1"><div></div></div><div class="gall2 img2"><div></div></div><div class="gall2 img3"><div></div></div>');
 var img = 0;
 for (var i=0; i<=2;i++){
	img = this.gall2.children('.img'+eval(i+1));
	img.css('background-image','url('+this.images['.gall2'].get(i).src+')');
 }
 setTimeout("gallery('.gall2')", 3000);
 this.lastSelect = Array();
 this.lastSelect['.gall2'] = i;
};

function gallery(sel){
	var img = 0;
	for (var i=0; i<=2;i++){
		img = this.gall2.children('.img'+eval(i+1));
		this.lastSelect[sel]++;
		if (this.lastSelect[sel]==this.images[sel].length){this.lastSelect[sel]=0;}
		img.fadeOut(1000, "changeImage("+this.gall2[0].id+",'.img"+eval(i+1)+","+this.images[sel].get(this.lastSelect[sel]).src+")");
	}
 setTimeout("gallery('"+sel+"')", 3000);
}

function changeImage(	sel,img,src){
	var img=$('#'+sel+'>'+img);
	if (img.length==0){return;}
	img.css('background-image','url('+src+')');
	img.fadeIn(1000);
}

function gallery1 (){
 var scrl = parseInt((Math.random() * this.gall1[0].clientHeight)/146.667)*146;
 this.gall1.fadeTo('slow',0.2,function(){$('#gall1').animate({scrollTop:scrl+'px'}, 'slow',function(){$('#gall1').fadeTo('slow',1)})});
 setTimeout("gallery1()", 6200);
}

function gallery2 (){
 var scrl = parseInt((Math.random() * this.gall2[0].clientHeight)/146.667)*146;
 this.gall2.fadeTo('slow',0.2,function(){$('#gall2').animate({scrollTop:scrl+'px'}, 'slow',function(){$('#gall2').fadeTo('slow',1)})});
 setTimeout("gallery2()", 6000);
}

function InitGallOtdel(){
	var gal = $('a.dir');
	if (gal.length==0){return;}
	for (var i=0; i < gal.length; i++)
	{
		var t = gal[i].id.match(/dir(\d+)/i);
		var fot = $('#otdel'+t[1]);
		if (fot != null){
			$('#'+t[0]).click(ShowHide);
			fot.slideUp('0');
			//fot.set('slide', {duration: 'long'});
			//fot.slide('out');
		}
	}
	//gal.slideUp('fast');
}

function ShowHide(eventObject) {
	var t = this.id.match(/dir(\d+)/i);
	var fot = $('#otdel'+t[1]);
	if (fot != null){
		fot.slideToggle('slow');
	}
	return false;
}


$(document).ready(function() {
 //sliderGallery();
 InitGallOtdel();
 });

