function Slider(ele,left,right)
{
	this.current = 0;
    this.items = $(ele).getElementsByTagName('li');
    this.count = this.items.length;
    
    for(i=0;i<this.count;i++)
        if(i!=0) this.items[i].style.display = 'none';

    this.slide = function(direction)
    {
    	Effect.Fade(this.items[this.current]);
        if(direction == 'fw')
            if (this.current == (this.count-1)) { this.current = 0; } else { this.current++; }
        else
            if (this.current == 0) { this.current = (this.count-1); } else { this.current--; }
        Effect.Appear(this.items[this.current]);
    };
    
    $(right).observe('click',this.slide.bindAsEventListener(this,'fw'));
    $(left).observe('click',this.slide.bindAsEventListener(this,'prev'));
}


// JavaScript Document
// "global" variables
var cur_sec1 = 0;
var cur_side1 = 0;
var cur_sec2 = 0;
var cur_side2 = 0;
var current_frame;
var current_frame1;
var current_frame2;
var images_count;
var images_count1;
var images_count2;
var lame_slider;
var title1_slider;
var title2_slider;

document.observe('dom:loaded', function()
{
	// loop thru all images and hide them
	current_frame = 0;
	current_frame1 = 0;
	current_frame2 = 0;
	
	lame_slider = $('top-image').getElementsByTagName('li');
	title1_slider = $("slider1").getElementsByTagName("li");
	title2_slider = $("slider2").getElementsByTagName("li");

	l1 = new Slider('gal-left','left-gal-left','left-gal-right');
	r1 = new Slider('gal-right','right-gal-left','right-gal-right');
	
	for(i=0;i<lame_slider.length;i++) if(i!=0) lame_slider[i].style.display = 'none';
	for(i=0;i<title1_slider.length;i++) if(i!=0) title1_slider[i].style.display = 'none';
	for(i=0;i<title2_slider.length;i++) if(i!=0) title2_slider[i].style.display = 'none';
	
	var go = new PeriodicalExecuter(function() {
			slide('fw');										 
	},6);
	
	var go_title1 = new PeriodicalExecuter(function() {
			cur_sec1++;
			if(cur_sec1 == 4 && cur_side1 == 0) {
				slide_title1("fw");
				cur_side1 = 1;
				cur_sec1 = 0;
			} else if(cur_sec1 == 1 && cur_side1 == 1) {
				slide_title1("fw");			
				cur_side1 = 0;
				cur_sec1= 0;
			}
	},1);
	
	var go_title2 = new PeriodicalExecuter(function() {
			cur_sec2++;
			if(cur_sec2 == 4 && cur_side2 == 0) {
				slide_title2("fw");
				cur_side2 = 1;
				cur_sec2 = 0;
			} else if(cur_sec2 == 1 && cur_side2 == 1) {
				slide_title2("fw");
				cur_side2 = 0;
				cur_sec2 = 0;
			}
	},1);

});




function slide(direction)
{
	// hide current image
	images_count = lame_slider.length-1;
	Effect.Fade(lame_slider[current_frame],{duration: 3});
	if(direction == 'fw')
		if (current_frame == images_count) { current_frame = 0; } else { current_frame++; }
	else
		if (current_frame == 0) { current_frame = images_count; } else { current_frame--; }
	// and show next or previous
	Effect.Appear(lame_slider[current_frame],{duration: 3});
}

function slide_title1(direction)
{
	// hide current image
	images_count1 = title1_slider.length-1;
	Effect.Fade(title1_slider[current_frame1],{duration: 0.5});
	if(direction == 'fw')
		if (current_frame1 == images_count1) { current_frame1 = 0; } else { current_frame1++; }
	else
		if (current_frame1 == 0) { current_frame1 = images_count1; } else { current_frame1--; }
	// and show next or previous
	Effect.Appear(title1_slider[current_frame1],{duration: 0.5});
}

function slide_title2(direction)
{
	// hide current image
	images_count2 = title2_slider.length-1;
	Effect.Fade(title2_slider[current_frame2],{duration: 0.5});
	if(direction == 'fw')
		if (current_frame2 == images_count2) { current_frame2 = 0; } else { current_frame2++; }
	else
		if (current_frame2 == 0) { current_frame2 = images_count2; } else { current_frame2--; }
	// and show next or previous
	Effect.Appear(title2_slider[current_frame2],{duration: 0.5});
}

