$(document).ready(rebind);
function rebind()
{
	//see if we are on the home page first
/*	if (!$('#contents').hasClass('home_page')) {
		$('#contents .template_1 h1').each(modify_titles);
		$('#contents .template_2 h1').each(modify_titles);
		$('#contents .template_1 li').each(modify_lists);
		$('#contents .template_2 li').each(modify_lists);
	}*/
	
	
	//var back_to_top='<a href="javascript:top();" class="back">Back to Top</a>'; 
	//$('#contents .block').append(back_to_top);
	
	var current_image=$('#middle_header').css('backgroundImage').split('banner');
	current_image=Number(current_image[1].replace('.jpg)',''));
	if (!isNaN(current_image)) {
		slide_timeout();
	}
}
var next_image=0;
function slide_timeout()
{
	var current_image=$('#middle_header').css('backgroundImage').split('banner');
	current_image=Number(current_image[1].replace('.jpg)',''));
	
	if (next_image>0) {
		$('#middle_header').css('backgroundImage','url(/html/tplf/images/banner'+next_image+'.jpg)');
	}
	
	
	next_image++;
	
	if (next_image>8) {
		next_image=1;
	}
	
	var preload= new Image(570,191);
	preload.src="/html/tplf/images/banner"+next_image+".jpg"; 
	
	
	old_image=current_image;

	setTimeout(slide_timeout,5000);	
}
function top()
{
	$('html').attr('scrollTop','0');;
}
function modify_titles()
{
	var text=$(this).text();
	text=text.split(' ');
	var title_text='';
	
	for (i=0;i<text.length;i++) {
		if (i==0) {
			text[i]='<span>'+text[i]+'</span>';
		}
		title_text+=text[i]+' ';
	}
	$(this).html(title_text);

}
function modify_lists()
{
	$(this).html('<span class="color">'+$(this).html()+'</span>');
	$(this).addClass('color');
}