$(function(){
	/***********************
	 * home page
	***********************/
	//banner fadein/fadeout images
	var banner_title_link,
	    banner_navi,
		changing = false,
		active_class = 'active';
	$('#banner').append('<h3 id="banner_title"><a href="#"></a></h3><ul id="banner_navi"></ul>').find('img').each(function(i){
		var t = this;
		t.id = 'no_'+(i+1);
		//fill in the first banner infomation
		if(i===0){
			banner_title_link = $('#banner_title a');
			banner_navi       = $('#banner_navi');			
			banner_title_link.text(t.alt)[0].href = t.title;
		}else{
			$(this).hide();
		}
		//create navi bar
		$('<li><span><i>'+(i+1)+'</i></span></li>').appendTo(banner_navi).click(function(){
			var siblings = $(t).siblings('img').css({'z-index':0}).stop(true, true);
			$(t).css('z-index','10').fadeIn(400,function(){
				siblings.hide();
			});
			banner_title_link.text(t.alt)[0].href = t.title;
			$(this).addClass(active_class).siblings('li').removeClass(active_class);
		}).addClass(function(){
			return i===0 ? active_class : '';
		});
	});

	/***********************
	 * testimonials page
	***********************/
	var testimonals = $('#testimonials');
	//images toggle
	testimonals.find('.thumbnail img').click(function(){
		$(this).parent().prev().find('img').eq($(this).index()).show().siblings().hide();
	});
	//vertical centered the 'content div' in testimonials item
	var full_height = 239,
	    true_height;
	testimonals.find('.content').each(function(){
		true_height = $(this).height();
		if(true_height<239){
			$(this).css({paddingTop:(full_height-true_height)*.5});
		}
	});
	
	/***********************
	 * services page
	***********************/
	//images toggle
	$('#services').find('.thumbnail img').click(function(){
		$(this).parent().prev().find('img').eq($(this).index()).show().siblings().hide();
	});	

});
