var img_mass = new Array();
var SwitchDuration=0.30;
var time_duration=0.0;
var part_block=false;
var block=false;
var right_l=0;
var Blocked;
var count=0;
var scion;
var time;


ImageSlide.prototype.init=function(){
	elem = document.getElementById('slide_div');
	if (!elem) {return false;}
	this.scion = elem.childNodes;
	scion = this.scion;
	for (var i=0; i<=(scion.length-1); i++) {
		img_mass[i] = 523+1;
		scion[i].style.right = right_l+'px';
		right_l += img_mass[i];
	}
	var proxy=document.createElement('div');
	proxy.style.position = 'absolute';
	proxy.style.right = right_l + 'px';
	proxy.style.width = right_l+'px';
	proxy.innerHTML = elem.innerHTML;
	document.getElementById('slide_div').parentNode.insertBefore(proxy, document.getElementById('slide_div'));
	
	count = (0);
	document.getElementById('img_info').innerHTML = scion[count].firstChild.alt;
	if (scion[count].firstChild.name=='h_big') {
		document.getElementById('img_info').previousSibling.style.display = 'block'; }
		else { document.getElementById('img_info').previousSibling.style.display = 'none';
	}
	document.getElementById('img_info').previousSibling.href = scion[count].firstChild.longDesc;
}


ImageSlide.prototype.slide_right=function() {
		if (Blocked) return; Blocked = true;
		if (count==(scion.length-1)) {
			new Effect.Move(document.getElementById('slide_div_wrap'), { x: 524, y: 0, duration: SwitchDuration});
			setTimeout(function() {
				document.getElementById('slide_div_wrap').style.left = '0px';
			}, 1100*SwitchDuration);
			count = 0;
		} else {
			new Effect.Move(document.getElementById('slide_div_wrap'), { x: 524, y: 0, duration: SwitchDuration});
			count++;
		}
		document.getElementById('img_info').innerHTML = scion[count].firstChild.alt;
		if (scion[count].firstChild.name=='h_big') {
			document.getElementById('img_info').previousSibling.style.display = 'block';
		} else {
			document.getElementById('img_info').previousSibling.style.display = 'none';
		}
		document.getElementById('img_info').previousSibling.href = scion[count].firstChild.longDesc;
		setTimeout(function(){Blocked=false;}, 2000*SwitchDuration);
}



function button_up () {
	if (time) {
		timeclear();
	}
	if (block==false) {
		new Effect.Appear('slide_but', {duration: time_duration});
		setTimeout(function() {
			block = true;
		}, 1500*time_duration);
	} else if (part_block) {
		setTimeout(function() {
			new Effect.Appear('slide_but', {duration: time_duration});
			part_block = false;
			block = true;
		}, 1500*time_duration);
	}
}
function timeclear () {
	clearTimeout(time);
}
function timestart () {
	if (block) {
		timeclear();
		time = setTimeout(function() {
			part_block = true;
			setTimeout(function() {
				new Effect.Fade('slide_but', { duration: time_duration });
				block = false;
				part_block = false;
			}, 1000*time_duration);
		}, 1000*time_duration );
	}
}



function sl(num) {
	var it = num - count;
	new Effect.Move(document.getElementById('slide_div_wrap'), { x: 524*it, y: 0, duration: SwitchDuration});
	count = count + it;
}



function ImageSlide() {}
mImageSlide=new ImageSlide();
document.observe('dom:loaded', function(){
	//mImageSlide.init()
	!document.getElementById('p_alt') ? mImageSlide.init() : '';
//	$$('h1').each(function(){
//		observe('click', function() {
		//alert('fs');
//		});
//	});
});
