/*

	HR and Training Solutions
	http://www.hrandtrainingsolutions.co.uk/
	
	Systemagic
	http://www.systemagic.co.uk/

*/

$(document).bind("ready", function(){
				   
	$('body').addClass("javascript");	
	
	$("*[href]:not(a)").bind("click", function(){
		window.location = $(this).attr("href");	
	});
	
	$("div.header input").bind("blur", function(){
		if($(this).val() == ""){
			$(this).val(searchLabel);
			$(this).addClass("label");
		}
	});
	
	$("a.read-more").bind("click", function(){
		id = $(this).attr("href");
		$(id).slideDown(200);
		return false;
	});
	
	$("a.pop-more").bind("click", function(){
		html = "<div class=\"scroll white\">" + $($(this).attr("href")).html() + "</div>";
		html = html.replace(/comment-top.jpg/gi, "comment-white-top.jpg");
		$(this).message({ title:$(this).attr("title"), "message":html }, {
			"Close":"cancel"
		});
	});
	
	$('.clickable').bind("click", function(){
		window.location = $(this).find("a:first").attr("href");
	});
	
	jQuery.fn.extend({
		getCurrentAndNext: function(filter){
			current = $(this).find(filter + "[current]");
			
			len  = $(this).find(filter + "[current]").next().length;
			if(len >= 1){
				next = $(this).find(filter + "[current]").next();
			}else{
				next = $(this).find(filter + ":first");
			}
			
			$(current).removeAttr("current");
			$(next).attr("current", "true");
			
			return [current, next];
		}
	});
	
	if($('.banner').length){

		$('.banner .item:not(:first)').fadeOut(0);
		$('.banner .item:first').attr("current", "true");
		
		updateBanner = function(){
			nextCurrent = $('.banner').getCurrentAndNext(".item");
			
			current = nextCurrent[0];
			next	= nextCurrent[1];
			
			$('.banner').animate({ 'height':$(next).height()+15 }, 200);
			
			$(current).fadeOut(400);
			$(next).fadeIn(400);
		}
		
		$('.banner').animate({ 'height':$('.banner .item:first').height()+15 }, 200);
		
		setInterval(updateBanner, 5000);
	}
	
});
