$(document).ready(function(){

	$("img.png24").pngfix();

	if($("a.colorbox").length) $("a.colorbox").colorbox();

	if($(".fade").length) {
		$(".fade").innerfade({
			speed: "5000",
			timeout: "10000"
		});
	}

	if($("#partners .colgroup > ul").length) {
		$("#partners .colgroup > ul").innerfade({
			speed: "1000",
			timeout: "10000",
			containerheight: "48px",
			animationtype: 'fade'
		});
	}

	if($("#banner .colB .boxC ul").length) {
		$("#banner .colB .boxC ul").innerfade({
			speed: "1000",
			timeout: "4000",
			containerheight: "156px",
			animationtype: 'fade'
		});
	}

	$(document).click(function(e){
		if(!$(e.target).parents(".bubble").length) $(".bubble").hide();
	});

	$("#team .col .preview .testimonial a.btn").click(function(){
		$(".bubble").not($(this).next(".bubble")).hide();
		$(this).next(".bubble").toggle();
		return false;
	});

	/* Case Studies */

	if($("#case-studies").length) {

		$("#case-studies .case-study").hide();

		var myFile = document.location.toString();

		if (myFile.match('#')) {
		  var myAnchor = '#case-study-' + myFile.split('#')[1];
		  $("#case-studies .listA a.on").removeClass("on");
		  $("a[href="+myAnchor+"]").addClass("on");
		  $(myAnchor).show();
		} else {
		  $("#case-studies .table-of-contents li > a.on").show_fragment();
		}

		$("#case-studies .table-of-contents li a").click(function(){
			var parent = $(this).parents(".table-of-contents");
			$("li > a.on", parent).hide_fragment();
			$(this).show_fragment();
			return false;
		});

		$("#case-studies .case-study a.next").click(function(){
			var selected = $("#case-studies .table-of-contents li > a.on");
			$(selected).hide_fragment();
			selected.parent("li").next("li").find("a").show_fragment();
			return false;
		});

	}

});

$.fn.show_fragment = function() {
	var fragment = $(this).attr("href");
	$(this).addClass("on");
	$(fragment).show();
}

$.fn.hide_fragment = function() {
	var fragment = $(this).attr("href");
	$(this).removeClass("on");
	$(fragment).hide();
}
