$(document).ready(function(){
	captionSliding();
	panels();
	sidebarGroups();
	tabs();
	nobreak();
});

function captionSliding() {
	var slide_duration = 160;
	$('.boxgrid.caption').hover(function(){
		$(".cover", this).stop().animate({top:'72px'},{queue:false,duration: slide_duration});
	}, function() {
		$(".cover", this).stop().animate({top:'136px'},{queue:false,duration: slide_duration});
	});
}

function panels() {
	$("ul.panel-nav a").click(function() {
		var refId = $(this).attr("id");
		$(".panels .shown").fadeOut("fast", function() {
			$(".panels .shown").removeClass('shown');
			$("div." + refId).fadeIn("fast");
			$("div." + refId).addClass('shown');
		});
		$("ul.panel-nav a").removeClass('current');
		$(this).addClass('current');
		return false;
	});
 }
	 
function sidebarGroups() {
 	$(".parent").click(function() {
		$(this).next().slideToggle("fast");
 	});
}
	
function tabs() {
	var tabContainers = $('div.tabs > div');
	tabContainers.hide().filter(':first').show();
	$('div.tabs ul.tab-nav a').click(function () {
			tabContainers.hide();
			tabContainers.filter(this.hash).show();
			$('div.tabs ul.tab-nav a').removeClass('selected');
			$(this).addClass('selected');
			return false;
	}).filter(':first').click();
}

function nobreak() {
	$('span.nobreak, .nobreak a').each(function() {
		var newText = "";
		var textArray = $(this).text().split(" ");
		var wordCount = textArray.length;
		for(i=0; i <= (wordCount-1); i++) {
			newText += textArray[i];
			if(i != (wordCount-1)) {
				newText += "&nbsp;";
			}
		}
		$(this).html(newText);
	});
}



/*
 * Tooltip script 
 * powered by jQuery (http://www.jquery.com)
 * 
 * written by Alen Grakalic (http://cssglobe.com)
 * 
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 *
 */

this.tooltip = function(){	
	/* CONFIG */		
		xOffset = 32;
		yOffset = 0;		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$("a.tooltip").hover(function(e){											  
		this.t = this.title;
		this.title = "";
		$("body").append("<p id='tooltip'>"+ this.t +"</p>");
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.show();		
    },
	function(){
		this.title = this.t;		
		$("#tooltip").remove();
    });	
	$("a.tooltip").mousemove(function(e){
		$("#tooltip")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};


// starting the script on page load
$(document).ready(function(){
	tooltip();
});
