$(document).ready(function(){
	
	reinitSP();
	
});

function reinitSP(){
	
	$('#scrollText').jScrollPane({
		dragMinHeight: 130,
		dragMaxHeight: 130,
		wheelSpeed: 40,
		scrollbarWidth: 8,
		scrollbarMargin: 10,
		reinitialiseOnImageLoad: true
	});
	
	$(".client img").each(function(){
		var pic=new Image();
		pic.src= $(this).attr("src");
		
		if(pic.complete) $(this).parent().centerImage();
		else $(".client img").load(function(){
			$(this).parent().centerImage();
		});
	});
}

function allSlideOut(href) {

	$("#contentWrapper").fadeOut("fast",function(){
		$("#contentWrapperBg").animate({ width: 0 },"fast","linear",function(){
			$.ajax({
				type: "POST",
				url: href,
				data: "relAjax=1",
				
				beforeSend: function(req){
					$("#loader").show();
				},
				
				success: function(resp){
					$("#outerWrapper").html(resp);
				},
				
				complete: function(req, status){
					$("#loader").hide();
				}
				
			});
		});
	});

}

function allSlideIn() {

	$("#contentWrapperBg").animate({ width: 450 },
								   {duration: "fast", 
								   	easing: "linear",
								   	queue: true, 
								   	complete: function(){
										$("#contentWrapper").fadeIn("normal",function(){
											reinitSP();
										});
									}
	});
	

}

function loadSection(obj) {
	
	href = $(obj).attr("href");
	
	allSlideOut(href);
	
}

$.fn.centerImage = function() {
	
	
	
	return this.each(function () {
		
		containerHeight = $(this).height();
		img = $(this).find("img");
		
		
		imgHeight = img.height();
		
		//alert(img.attr("src")+": "+containerHeight+"-"+imgHeight);
		
		if(imgHeight < containerHeight) {
			
			ch = Math.round(containerHeight/2);
			ih = Math.round(imgHeight/2);
			xtop = ch-ih;
			
			//alert(xtop);
			
			img.css({
				position: "relative",
				top: xtop + "px"
			});
			
		}
		
	});
	
};