$(document).ready(function() {
	if ($('div.home_page').length > 0) centerHomeText();
	if ($('#scrollable').length > 0) $('#scrollable').jScrollPane();
	if ($('a.tooltip').length > 0) jQtooltip();
	if ($('#home_images').length > 0) startHomeShow();
	if ($('#image_viewer').length > 0) imageSlideshow();
	if ($('#show_all_news').length > 0) showNews();
});

function centerHomeText() {	
	var wH = $('#main-right .wysiwyg').height();
	$('#main-right .wysiwyg').css('margin-top',-(wH/2));
}

function jQtooltip() {
	$('a.tooltip').tooltip({
		delay:0,
		track:true
	});
}

function startHomeShow() {
	var myInt = window.setInterval('homeSlideShow()',5000);
	$('ul#home_images').mouseenter(function() { 
		window.clearInterval(myInt);
	});
	$('ul#home_images').mouseleave(function() { 
		myInt = setInterval('homeSlideShow()',5000);
	});
}

function homeSlideShow(timeint) {
	
	var total = ($('ul#home_images li').length)-1;

	$('ul#home_images li.hit').each(function() {
		$(this).fadeOut(2000);
		var index = $('ul#home_images li').index(this);
		if (index >= total) {
			fade(0);
		} else {
			fade(index+1);
		}
	});
}

function fade(index) {
	$('ul#home_images li').attr('class','');
	$('ul#home_images li').eq(index).fadeIn(2000);
	$('ul#home_images li').eq(index).attr('class','hit')
}

function imageSlideshow() {	
	$('ul#project_thumbnails_list li a').click(function() {
		var index = $('ul#project_thumbnails_list li a').index(this);
		$('ul#project_thumbnails_list li a').attr('class','');
		$(this).attr('class','hit');
		$('ul#image_viewer li').fadeOut('normal');
		$('ul#image_viewer li').eq(index).attr('class','');
		$('ul#image_viewer li').eq(index).fadeIn('normal');
		$('ul#image_viewer li').eq(index).attr('class','hit');
		return false;
	});
}

function showNews() {
	$('#show_all_news').click(function() {
		$('#all_news').toggleClass('show');
		var show = ($('#all_news').hasClass('show')) ? true : false;
		var display = (show == false) ? 'SHOW ALL NEWS' : 'HIDE NEWS';
		$('#show_all_news').html(display);
		return false;
	});
}