$(document).ready(function() {
	// If a sidebar is empty because the widget login plugin "blocks" it,
	// remove the sidebar from JS because otherwise it is not possible
	if ( $("#sidebar").length && $("#sidebar").html().length < 10 ) {
		$("#sidebar").remove();
	}

	if ( $(".our-key-people:first").length ) {
		addOurKeyPeopleFunctionality();
	}

	if ( $(".kauscontact:first").length ) {
		$("#content:first").prepend( $(".entry-title:first") );
		$(".type-page:first").remove();
	}

	//Cufon.replace("body", {fontFamily: "Century Gothic"});
});


function addOurKeyPeopleFunctionality() {
	var speed = 200;
	var $mainObj = $(".our-key-people:first");

	// bind the click events on the name-links
	$mainObj.find("#intro:first .left:first a").click(function(e) {
		if ( ! $(this).hasClass("sel") ) {
			// get the number of the clicked name
			var item = parseInt(this.className);

			// remove selection from the previously selected name
			$mainObj.find("#intro:first .left:first a.sel").removeClass("sel");
			// add selection to the clicked name
			$(this).addClass("sel");

			// hide every previously active content
			// - change short biography
			$mainObj.find("#intro:first .short_bio:visible").fadeOut(speed, function() {
				$mainObj.find("#intro:first .short_bio:eq(" + item + ")").fadeIn(speed);
			});

			// - change main content title
			/*$mainObj.find("h1:first span:visible").fadeOut(speed, function() {
				$mainObj.find("h1:first span:eq(" + item + ")").fadeIn(speed);
			});*/

			// - change main content (long biography)
			$mainObj.find(".long_bio:visible").fadeOut(speed, function() {
				$mainObj.find(".long_bio:eq(" + item + ")").fadeIn(speed);
			});

			// - change contact data name
			$mainObj.find("#sidebar:first h3:first span:visible").fadeOut(speed, function() {
				$mainObj.find("#sidebar:first h3:first span:eq(" + item + ")").fadeIn(speed);
			});

			// - change email
			$mainObj.find(".email:first span:visible").fadeOut(speed, function() {
				$mainObj.find(".email:first span:eq(" + item + ")").fadeIn(speed);
			});

			// - change telephone
			$mainObj.find(".tel:first span:visible").fadeOut(speed, function() {
				$mainObj.find(".tel:first span:eq(" + item + ")").fadeIn(speed);
			});

			var $imgObj			= $mainObj.find("#intro:first .img:first img:first");
			var imgObjNewSrc	= $imgObj.nextAll("input:eq(" + item + ")").val();
			if ( $.browser.msie ) speed = 0;
			$imgObj.fadeOut(speed, function() {
				$imgObj
					.removeAttr("width")
					.removeAttr("height")
					.attr("src", imgObjNewSrc)
				;
				$imgObj.fadeIn(speed);
			});
		}
		return false;
	});
}
