var projectsPos = 0;
var studioPos = 0;
var alsioPos = 0;

//var projectTotal = 0;
var moving=false;


window.onload = function() {

//alert("");
//document.getElementsByTagName('alsio_left')[0].getElementsByTagName('studio_left_arrow')[0].style.visibility="hidden";
 //document.body.all.tags("studio_left_arrow").style.visibility="hidden";
 //alert(document.body.all.tags("studio_left_arrow");
 	//document.getElementById('mask-1').onmouseover=hideMask;
 	//hideMask(document.getElementById('mask-1'));

 	
	document.getElementById('studio_left').childNodes[0].style.visibility="hidden";
	document.getElementById('alsio_left').childNodes[0].style.visibility="hidden";
	document.getElementById('projects_left').childNodes[0].style.visibility="hidden";


	//console.log(projectTotal);
	var cc=0;
	var projectsTotal = document.getElementById('projects_items').childNodes.length;
	for (var i=0; i<projectsTotal; i++){
		if(document.getElementById('projects_items').childNodes[i].nodeType==1){
		cc++;
		}
	}
	//projectsTotal=projectsTotal/2;
 	projectsTotal=cc-3;
 	
 	//alert(projectsTotal);



	document.getElementById('projects_right').onclick = function(){
	if(moving==false && projectsPos<=projectsTotal){
	slide('projects_items', 250,-1,projectsPos);
	projectsPos++;
	if(projectsPos>projectsTotal) document.getElementById('projects_right').childNodes[0].style.visibility="hidden";
	else document.getElementById('projects_right').childNodes[0].style.visibility="visible";
	 if(projectsPos<0) document.getElementById('projects_left').childNodes[0].style.visibility="hidden";
	else  document.getElementById('projects_left').childNodes[0].style.visibility="visible";
	}
	};
	
	document.getElementById('projects_left').onclick = function(){ 
	if(moving==false && projectsPos>=0){
	slide('projects_items',250,1,projectsPos);
	projectsPos--;
	if(projectsPos>projectsTotal) document.getElementById('projects_right').childNodes[0].style.visibility="hidden";
	else document.getElementById('projects_right').childNodes[0].style.visibility="visible";
	 if(projectsPos<0) document.getElementById('projects_left').childNodes[0].style.visibility="hidden";
	else  document.getElementById('projects_left').childNodes[0].style.visibility="visible";
	}
	};
	
	cc=0;
	var alsioTotal = document.getElementById('alsio_items').childNodes.length;
	for (var i=0; i<alsioTotal; i++){
		if(document.getElementById('alsio_items').childNodes[i].nodeType==1){
		cc++;
		}
	}
	alsioTotal=cc-3;

	document.getElementById('alsio_right').onclick = function(){
	if(moving==false && alsioPos<=alsioTotal){
	slide('alsio_items',250,-1,alsioPos);
	alsioPos++;
	if(alsioPos>alsioTotal) document.getElementById('alsio_right').childNodes[0].style.visibility="hidden";
	else document.getElementById('alsio_right').childNodes[0].style.visibility="visible";
	 if(alsioPos<0) document.getElementById('alsio_left').childNodes[0].style.visibility="hidden";
	else  document.getElementById('alsio_left').childNodes[0].style.visibility="visible";


	}
	};
	
	document.getElementById('alsio_left').onclick = function(){ 
	if(moving==false && alsioPos>=0){
	slide('alsio_items',250,1,alsioPos);
	alsioPos--;
	if(alsioPos>alsioTotal) document.getElementById('alsio_right').childNodes[0].style.visibility="hidden";
	else document.getElementById('alsio_right').childNodes[0].style.visibility="visible";
	 if(alsioPos<0) document.getElementById('alsio_left').childNodes[0].style.visibility="hidden";
	else  document.getElementById('alsio_left').childNodes[0].style.visibility="visible";


	}
	};
	
	cc=0;
	var studioTotal = document.getElementById('studio_items').childNodes.length;
	for (var i=0; i<studioTotal; i++){
		if(document.getElementById('studio_items').childNodes[i].nodeType==1){
		cc++;
		}
	}
	studioTotal=cc-3;
	
	document.getElementById('studio_right').onclick = function(){
	if(moving==false && studioPos<=studioTotal){
	slide('studio_items', 250,-1,studioPos);
	studioPos++;
	if(studioPos>studioTotal) document.getElementById('studio_right').childNodes[0].style.visibility="hidden";
	else document.getElementById('studio_right').childNodes[0].style.visibility="visible";
	 if(studioPos<0) document.getElementById('studio_left').childNodes[0].style.visibility="hidden";
	else  document.getElementById('studio_left').childNodes[0].style.visibility="visible";


	}
	};
	
	document.getElementById('studio_left').onclick = function(){ 
	if(moving==false && studioPos>=0){
	slide('studio_items',250,1,studioPos);
	studioPos--;
	
	if(studioPos>studioTotal) document.getElementById('studio_right').childNodes[0].style.visibility="hidden";
	else document.getElementById('studio_right').childNodes[0].style.visibility="visible";
	 if(studioPos<0) document.getElementById('studio_left').childNodes[0].style.visibility="hidden";
	else  document.getElementById('studio_left').childNodes[0].style.visibility="visible";
	}
	};
	
		

}


	function slide(_id,_moves,_dir,_position)
	{

		var el = document.getElementById(_id);
		_moves = _moves*.90;
						
		var m;
		if(_dir>0){
			m = (-251*_position)+(251-_moves);
		}
		else{
			m = (-251*_position)-(251-_moves);
		}
		

			el.style.left= m +'px';
			
			if(_moves>=1)
			{
			
				setTimeout(function(){slide(_id,_moves,_dir,_position)},10);
	
				moving=true;
			}
			else
			{
				moving=false;
			}
	}
	
	
function stretch(_id,_start,_end)
	{

		var el = document.getElementById(_id);
		//_moves = _moves*.90;
						
		_start*=1.05;

		
			el.style.width= _start +'px';
			
			if(_start<=_end)
			{
			
				setTimeout(function(){stretch(_id,_start,_end)},10);
	
			}

	}
	
function shrink(_id,_start,_end)
	{
		var el = document.getElementById(_id);
		//_moves = _moves*.90;					
		_start*=.95;
			el.style.width= _start +'px';			
			if(_start>=_end)
			{		
				setTimeout(function(){shrink(_id,_start,_end)},10);
			}

	}	
	

function hideMask(){
//_el.style.visibility='hidden';
var w=document.getElementById('mask-1').clientWidth;
if(w<300){
stretch('mask-1',1,500);
shrink('wrap',786,275);	
//shrink('content-home',786,275);		
	
}
else if(w>450){
shrink('mask-1',500,1);
stretch('wrap',275,786);
//stretch('content-home',275,786);

}
}




//to clean ie childnode finding	
var notWhitespace = /\S/;

function cleanWhitespace(node) {
  for (var x = 0; x < node.childNodes.length; x++) {
    var childNode = node.childNodes[x]
    if ((childNode.nodeType == 3)&&(!notWhitespace.test(childNode.nodeValue))) {
// that is, if it's a whitespace text node
      node.removeChild(node.childNodes[x])
      x--
    }
    if (childNode.nodeType == 1) {
// elements can have text child nodes of their own
      cleanWhitespace(childNode)
    }
  }
}

