
var activeSection = "torusoft";

var sections = new Object();

sections['torusoft'] = {'id': 'torusoft', 'section': 'torusoftSection'};
sections['services'] = {'id': 'services', 'section': 'servicesSection'};
sections['reading'] = {'id': 'reading', 'section': 'readingSection'};
sections['highlights'] = {'id': 'highlights', 'section': 'highlightsSection'};
sections['contact'] = {'id': 'contact', 'section': 'contactSection'};


var subsections = new Object();

subsections['services'] = { 'design': {id: "design", section: 'designSection'},
						 'development': {id: "development", section: 'developmentSection'},
						 'consulting': 	{id: "consulting", section: 'consultingSection'}						 
						}
					
subsections['reading'] = { 'dashboard': {id: "dashboard", section: 'dashboardSection'},
						 'products': {id: "products", section: 'productsSection'},
						 'blog': {id: "blog", section: 'blogSection'},
						 'downloads': 	{id: "downloads", section: 'downloadsSection'}						 
						}
						
 
var activeSubSection = {"services": "consulting", "reading": "dashboard"} 


function displaySection(choice){
	prevSection = activeSection;
	activeSection = choice;
	rollOff(prevSection);
	$(sections[choice].id).className = 'active';	
	Effect.Fade(sections[prevSection].section, {duration: 0.25});			
	Effect.Appear(sections[activeSection].section, {duration: 0.25, queue: 'end', afterFinish: setScroller});
}

function rollOn(which){
	if(which != activeSection)		
		$(sections[which].id).className = 'active';		
	if('alias' in sections[which])
		//$(sections[sections[which].alias].id).src = 'images/' + sections[sections[which].alias].active;
		$(sections[sections[which].alias].id).className = 'active';	
}
function rollOff(which){
	if(which != activeSection)
		$(sections[which].id).className = 'inactive';
	if(('alias' in sections[which]) && (sections[sections[which].alias].alias != which))
		//$(sections[sections[which].alias].id).src = 'images/' + sections[sections[which].alias].inactive;
		$(sections[sections[which].alias].id).className = 'inactive';
}

function displayContent(choice){   //newest
	if(choice != activeSubSection[activeSection]){
		prevSubSection = activeSubSection[activeSection];
		activeSubSection[activeSection] = choice;		
		if(subsections[activeSection][choice].id != subsections[activeSection][prevSubSection].id)
			rollOffSub(prevSubSection);
			$(subsections[activeSection][choice].id).className = 'active';
		Effect.Fade(subsections[activeSection][prevSubSection].section, {duration: 0.25});
		Effect.Appear(subsections[activeSection][choice].section, {delay: 0.5, duration: 0.25, afterFinish: setScroller});
	}
}


function rollOnSub(which){
	if(which != activeSubSection[activeSection]){
		if((subsections[activeSection][which].section != subsections[activeSection][activeSubSection[activeSection]].section))
			try { $(subsections[activeSection][which].id).className = 'active'; } catch(error){};
	}
}
function rollOffSub(which){
	if(which != activeSubSection[activeSection]){
		if((subsections[activeSection][which].section != subsections[activeSection][activeSubSection[activeSection]].section))
			try { $(subsections[activeSection][which].id).className = 'inactive'; } catch(error){};
	}
}

var tertiaryTracker = new Object();

function tertiaryController(list){
	newKey = Object.keys(tertiaryTracker).length;
	tertiaryTracker[newKey] = Object.clone(list);
	for(var n in list){
		Event.observe(n, 'click', window.revealTertiary.bindAsEventListener(this, newKey, list[n]));
	}		
	return newKey;
}


function revealTertiary(event, key, which){
	if(event)
		x = Event.element(event);
	for(var n in tertiaryTracker[key]){
		if($(n).className == "active"){
			$(n).removeClassName('active');
			$(n).addClassName('inactive');
			Effect.Fade(tertiaryTracker[key][n], {duration: 0.1, queue: 'end'});
		}
	}
	if(event){
		if(x.inspect().indexOf("small") != -1)
			x = x.up();
		x.addClassName('active');
		x.removeClassName('inactive');
	}
	Effect.Appear(which, {queue: 'end', duration: 0.2});
}

function setScroller(){
	if(!onSmartphone)
		return;
	if(activeSection != 'reading')
		return;
	if(activeSubSection[activeSection] == 'products') 
		productController.blogScroller.setupScroller(true);
	if(activeSubSection[activeSection] == 'blog'){
		blogController.blogScroller.setupScroller(true);
	}
	if(activeSubSection[activeSection] == 'dashboard'){
		deliciousScroller.setupScroller(true);
		twitterScroller.setupScroller(true);
	}
	
}



function btnHover(thisbtn)
{
	var tb = thisbtn;
	$(tb).className = 'hover';
}


function btnOut(thisbtn)
{
	var tb = thisbtn;
	$(tb).className = 'inactive';
}

function btnClick(which){$(which).removeClassName('inactive'); $(which).addClassName('pressed'); setTimeout(function(){$(which).removeClassName('clicked'); $(which).addClassName('inactive');}.bind(which), 100);}


delicious = new ajaxObject("AJAX/delicious.lasso");
delicious.callback = function(responseText, responseStatus){
	the_links = eval(responseText);
	
	for(i = (the_links.length-1); i != 0; i--){
		dstr = the_links[i].dt.substr(0,10);
		dstr = dstr.split('-');
		dstr = dstr[1] + "-" + dstr[2] + "-" + dstr[0];
		$('deliciousFeed').insert({ top: "<div class='delEntry'><div class=delDate>" + dstr + " : </div><div class='delLinkTitle'><a href='" + the_links[i].u + "' target=_blank><h4>" + the_links[i].d + "</h4></a></div><p>\"" + the_links[i].n + "\"</p></div>"});
	}
	if(onSmartphone){
		window.deliciousScroller = new TouchScroll(document.getElementById('deliciousFeed'), {elastic: true});
	}

}

twitter = new ajaxObject("AJAX/twitter.lasso");
twitter.callback = function(responseText, responseStatus){
	eval(responseText);
}

function pop()
{
	$('overlay').appear({duration: 0.2});
	$('fb').insert(test3());
	
}

function closePop()
{
	$('overlay').fade({duration: 0.2});
}


function sendMessage(){
	createMessage.update($('contactTorusoftForm').serialize());
}

createMessage = new ajaxObject("AJAX/send_message.lasso");
createMessage.callback = function(responseText, responseStatus){
	if(responseStatus == 200){
		$('contactFormContainer').update().insert("<div align='center' style='margin-top: 160px;'><img src=images/img_stamp.png width=250 height=200 alt='Your message has been sent.' /><br /><br /><h3>Thank You.<br><br>Your message has been submitted.<br><br>We'll be in touch soon.</h3></div>");
	}
	else{
		alert("There was a problem with your message. Please try again.");
	}
}







