var three_count = 0;
function startUp(){
	hideElement("text")
	hideElement("text2")
	hideElement("text3")
	hideElement("text3basket")
}
var string1 = "instead of time there was a sudden manhattan "
function growBoxes(color, step, id, round, length){
	// Morph($('box'), {"style":{"width":"1100px", "height":"1100px"}, duration:5})
	if(id<=length){
		log('worked: ', color, step, id)
		if(id==37)
			var div = DIV({'id': 'box'+ round + id ,'onclick':'morphBoxes({"width":"20px", "height":"1100px"});showText();','class': 'box', 'style' : {'opacity' : '0', 'filter':'alpha(opacity:0)','background-color' : '#' + dec2hex(color)}});
		else
			var div = DIV({'id': 'box'+ round + id , 'class': 'box', 'style' : {'opacity' : '0', 'filter':'alpha(opacity:0)','background-color' : '#' + dec2hex(color)}});
		appendChildNodes('dump', div);
		div.innerHTML = string1[id]
		appear('box'+round+id, {duration:1, from:0, to:1})
		var timer = window.setTimeout(function(){growBoxes(color+step, Math.round(1.41*step), id+1, round, length)}, 100);
		
	} else {
		clearTimeout(timer)
	}

}
function moveandgrow(obj, options){
	var box = $(obj)
		box.innerHTML = ""
	Morph(box, {"style": options, duration:1, afterFinish:function(){
		
	}})
	
}
function morphBoxes(options){
	for(var i = 0; i<=44; i++){
		moveandgrow("box1" + i, options);
	}
	
}
function showText(){
	moveandgrow("box137", {"width":"200px"});
	appear("text")
}
function showText2(){
	morphBoxes({"width":"100px"})
	appear("text2")
}
function showText3(){
	if(three_count >= 3){
		for(var i = 0; i<=44; i++){
			Morph('box1' + i, {"style": {"height":"0px"}, delay:1, duration:2, afterFinish:function(){
			if(i==44){
				window.location("http://proyekto.net/storyteller.html")
			}
			}})
		}
		
	}else{
		log(three_count)
		three_count++;
	}
}

function storyTellerLoad(){
	// hideElement('story')
	// hideElement('translate')
	hideElement('book')
	// appear('text3', {afterFinish:function(){
	// 	Morph('text3', {"style": {"height":"140px"}, duration:2, afterFinish:function(){
	// 		appear('story')
	// 		appear('translate')
	// 	}})
	// }})
}





function dec2hex(num)
{
	var newNum="";
	var result=num;
	var remainder=0;
	while (result>0)
	{
		result=Math.floor(num/16);
		remainder=num%16;
		num=result;

		if (remainder>=10)
		{
			if (remainder==10)
			remainder='A';
			if (remainder==11)
			remainder='B';
			if (remainder==12)
			remainder='C';
			if (remainder==13)
			remainder='D';
			if (remainder==14)
			remainder='E';
			if (remainder==15)
			remainder='F';
		}
		// just append the next remainder to the beginning of the string
		newNum=""+remainder+newNum;
	};
	//format for web use
	while(newNum.length<6)
	{
		newNum = "0" + newNum;
	}
	return newNum;
}
