function show_tab(tab, obj) {
	var blocks = ['body','related','recognition','process','interior'];
	var tabs = $('project_tabs').childNodes;
	for(var x=0;x<tabs.length; x++) {
		if(tabs[x].className) {
			Element.removeClassName(tabs[x],'active');					
		}
	}
	
	blocks.each( function(curr_block) {
		if(curr_block == tab) {
			if($(curr_block))
				Element.show(curr_block);
		} else {
			if($(curr_block))
				Element.hide(curr_block);
		}
	});
	
	if(tab == 'recognition' && recogNotInit) {
		initRecogCarousel();
	}
	
	if(tab == 'interior') {
		carousel.endScroll();
		
		if($('gallery_selector')) {
			var thumbs = $('gallery_selector').getElementsByTagName('li');
			changeImage(thumbs[thumbs.length-1]);
		}
	}
	
	Element.addClassName(obj.parentNode,'active');
}

var recogNotInit = true;

function initRecogCarousel() {

	var countExtras = 0;
	var itemsVisible = 0;
	var listHeight = 0;
	var isCounted = 0;	
	

	
	var viewPortHeight = $$('#recognition .carousel-clip-region')[0].offsetHeight;
	//console.log('viewport height: '+viewPortHeight);
	$$('#recognition .carousel-clip-region li').each(function(item, index){
		//console.log('index:' + index);
		if(item.offsetHeight > 16) {
			var extra = Math.floor((item.offsetHeight /16) -1);
			//console.log('extra lines:' + extra);
			countExtras += extra;
			//console.log(countExtras, 'countExtra lines');
		}
		if(isCounted == 0 && listHeight >= viewPortHeight) {
			itemsVisible = index + countExtras - 1;
			//console.log('got itemsVisible:' + itemsVisible + ' = ' + index + ' + ' + countExtras);
			isCounted = 1;
		}
		listHeight += item.offsetHeight;
		//console.log('listHeight: ' + listHeight);
	});
	var real_gallery_count =  $$('#recognition .carousel-clip-region li').length + countExtras;
	//console.log('real_gallery_count: ' + real_gallery_count);
	//console.log('itemsVisible: ' + itemsVisible);
	var carousel = new Carousel('recognition',  { 
         numVisible: itemsVisible, 
         scrollInc: 3, 
         size: real_gallery_count,
         scrollDirection: 'y',
         buttonStateHandler: handleGalleryButtonsRecognition, 
         animParameters: {duration: 0.4}, 
         prevElementID: 'recog_up', 
         nextElementID: 'recog_down'});
	recogNotInit = false;
}


function more_projects_show() {	
	$('more_projects_wrap').className = '';
	$('more_projects').className = '';
	$('more_overlay').className = '';
	return false;
}

function more_projects_hide() {
	$('more_projects_wrap').className = 'hide';
	$('more_projects').className = 'hide';
	$('more_overlay').className = 'hide';
	return false;
}


function project_back() {
	
	if(window.history.length > 1) {
		window.history.go(-1); return false;		
	} else {
		return true;
	}

}