// © 2009 SuperSite SRL
// Axiucit Alexandr

var urlref = '/';
var album = new Array;
var albumAct = 0;
var albumPages;
var albumAccess = 1;
var intervalID;

//---Initialize album---

/*if (document.getElementById('album').addEventListener)
    document.getElementById('album').addEventListener('load', function(){initAlbum()}, false);
else
    document.getElementById('album').attachEvent('onload', function(){initAlbum()});*/

function initAlbum(){
		arr = document.getElementById('album').firstChild.childNodes;
		albumPages = document.getElementById('album').firstChild;
		albumPages.style.marginLeft = 0;
		albumInterval = document.getElementById('album').firstChild.firstChild.offsetWidth;
		msg = '<img src="'+urlref+'img/design/arrow_l.gif" alt="" align="absmiddle" width="30" height="11" onClick="albumImg(\'prev\'); albumMove(\'prev\');">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
		for(i=0;i<arr.length;i++){
			album[i] = arr[i].offsetLeft;
			//msg += '<img src="'+urlref+'img/design/album_point.gif" alt="" width="11" height="15" onClick="albumImg('+i+'); albumPage('+i+');">&nbsp;&nbsp;&nbsp;';
			msg += '<a href="#1" alt="" onClick="albumImg('+i+'); albumPage('+i+'); return false;">'+(i+1)+'</a>&nbsp;&nbsp;&nbsp;';
		}
		msg += '&nbsp;&nbsp;&nbsp;<img src="'+urlref+'img/design/arrow_r.gif" alt="" align="absmiddle" width="30" height="11" onClick="albumImg(\'next\'); albumMove(\'next\');">';
		document.getElementById('albumPages').innerHTML = msg;
		if(arr.length == 1)
			document.getElementById('albumPages').style.display = 'none';
		albumImg(0);
}
function albumImg(page){
	if(page=='next')page = albumAct+1;
	if(page=='prev')page = albumAct-1;
	if((page>album.length-1)||(page<0)){/*alert(page+"="+albumAct);*/ page = albumAct; }

	if(albumAccess!=0){
		for(j=1;j<album.length+1;j++){
			//document.getElementById('albumPages').getElementsByTagName('img')[j].src = urlref+"img/design/album_pointb.gif";
			document.getElementById('albumPages').getElementsByTagName('A')[j-1].className = "";
		}
		//document.getElementById('albumPages').getElementsByTagName('img')[page+1].src = urlref+"img/design/album_point.gif";
		document.getElementById('albumPages').getElementsByTagName('A')[page+1-1].className = "act";
		//alert(page+1);
	}
}
//---albumMove([first, prev, next, last])---
function albumMove(action){
//---Next page---
	if((action=='next')&&(albumAccess==1)){
		if(album[albumAct+1]){albumAccess = 0;
			i=0.04;
			interval = album[albumAct+1];
			x=album[albumAct+1] - album[albumAct];
			albumAct++;
			intervalID = setInterval(function(){
				x = Math.ceil((x-1)/(1.01-i));
				albumPages.style.marginLeft = -(interval-x)+"px";
				if(i>-0.04)
				i-=0.002;
				if(x==0){albumPages.style.marginLeft = -interval+"px"; clearInterval(intervalID); albumAccess = 1;}
			}, 5);
		}
	}
//---Previous page---
	if((action=='prev')&&(albumAccess==1)){
		if((album[albumAct-1])||(album[albumAct-1]==0)){albumAccess = 0;
				i=0.04;
			interval = album[albumAct-1];
			x=album[albumAct] - album[albumAct-1];
			albumAct--;
			intervalID = setInterval(function(){
				x = Math.ceil((x-1)/(1.01-i));
				albumPages.style.marginLeft = -(interval+x)+"px";
				if(i>-0.04)
				i-=0.002;
				if(x==0){albumPages.style.marginLeft = -interval+"px"; clearInterval(intervalID); albumAccess = 1;}
			}, 5);
		}
	}
//---Last page---
	if((action=='last')&&(albumAccess==1)){
		if(album[albumAct+1]){albumAccess = 0;
			i=0.03;
			interval = album[album.length-1];
			x=album[album.length-1] - album[albumAct];
			albumAct = album.length-1;
			intervalID = setInterval(function(){
				x = Math.ceil((x-1)/(1.01-i));
				albumPages.style.marginLeft = -(interval-x)+"px";
				if(i>-0.03)
				i-=0.002;
				if(x==0){albumPages.style.marginLeft = -interval+"px"; clearInterval(intervalID); albumAccess = 1;}
			}, 5);
		}
	}
//---First page---
	if((action=='first')&&(albumAccess==1)){
		if((album[albumAct-1])||(album[albumAct-1]==0)){albumAccess = 0;
			i=0.03;
			interval = album[0];
			x=album[albumAct] - album[0];
			albumAct = 0;
			intervalID = setInterval(function(){
				x = Math.ceil((x-1)/(1.01-i));
				albumPages.style.marginLeft = -(interval+x)+"px";
				if(i>-0.03)
				i-=0.002;
				if(x==0){albumPages.style.marginLeft = -interval+"px"; clearInterval(intervalID); albumAccess = 1;}
			}, 5);
		}
	}
}

function albumPage(page){
	if(albumAccess==1){//alert(album[page]+"="+albumAct);
		if(((album[page])||(album[page]==0))&&(page != albumAct)){albumAccess = 0;
			i=0.03;
			dir = 1;
			interval = album[page];
			if(album[page]>album[albumAct]){
				x=album[page] - album[albumAct]; dir=1;}
			else{
				x=album[albumAct] - album[page]; dir=-1;}
			albumAct = page;
			intervalID = setInterval(function(){
				x = Math.ceil((x-1)/(1.01-i));
				albumPages.style.marginLeft = -(interval-x*dir)+"px";
				if(i>-0.03)
				i-=0.002;
				if(x==0){albumPages.style.marginLeft = -interval+"px"; clearInterval(intervalID); albumAccess = 1;}
			}, 5);
		}
	}
}










