// JavaScript Document

$(document).ready(function(){



//hide message_body after the first one
	$(".message_list .message_body:gt(0)").hide();
	$(".message_list .message_body:eq(0)").hide();
//	$(".message_list .message_head:eq(0)").removeClass("active");

//hide message li after the 5th
//	$(".message_list li:gt(4)").hide();

	//toggle message_body
	$(".message_head").click(function(){
	  $(this).next(".message_body").slideToggle(500)
	  return false;
	});

	//collapse all messages
	$(".collpase_all_message").click(function(){
 	  $("p.message_head").addClass("active");
	  $(".message_body").slideUp(500)
	  return false;
	});
	
	
	$(".open_all_message").click(function(){
	  $("p.message_head").removeClass("active");
	  $(".message_body").slideDown(500)
	  return false;
	});

	//show all messages
	$(".show_all_message").click(function(){
	  $(this).hide()
	  $(".show_recent_only").show()
	  $(".message_list li:gt(4)").slideDown()
	  return false;
	});

	//show recent messages only
	$(".show_recent_only").click(function(){
	  $(this).hide()
	  $(".show_all_message").show()
	  $(".message_list li:gt(4)").slideUp()
	  return false;
	});




	$("p.message_head").click(function(){
	  $(this).toggleClass("active");

	});



//global vars
	var searchBoxes = $(".text");
	var searchBox = $("#txtsearch");
	var searchBoxDefault = "Search";
	
	//Effects for both searchbox
	searchBoxes.focus(function(e){
		$(this).addClass("active");
	});
	searchBoxes.blur(function(e){
		$(this).removeClass("active");
	});
	
	//Searchbox2 show/hide default text if needed
	searchBox.focus(function(){
		if($(this).attr("value") == searchBoxDefault) $(this).attr("value", "");
	});
	searchBox.blur(function(){
		if($(this).attr("value") == "") $(this).attr("value", searchBoxDefault);
	});

});







$(function() {
	var winH=$(window).height();
	$('.whole-bg').css("height",winH+"px");								  
	$('.global-nav>li').hover(function(){
		$(this).addClass('hover');
	}, function(){
		$(this).removeClass('hover');
	});
	var sH=$('.side-bar').height();
	var bH=$('.content').height();
	if(sH  < bH){
		$('.side-bar').css("height",bH+"px");	
		}
});
$(function() {
		$('#dot-links a').click(function() {
		if(window.galleryTimer) {
			window.clearTimeout(window.galleryTimer);
			window.galleryTimer = null;
		}
		window.galleryTimer = window.setTimeout(animateGallery, 10000);
		$(this).parent().siblings().removeClass('sel');
		$(this).parent().addClass('sel');
		var img = new Image();
		var anchor = this;
		img.onload = function() {
			$('#mgmt-image').fadeOut('slow', function() {
				$('#mgmt-image').attr('src', img.src).fadeIn('slow');
				var href= $(anchor).parent().children('span').text();
				if(!href){
					href="javascript:;";
				}
				$('#spotlink').attr('href', href);
			});
			$('#services-block h3').fadeOut('slow', function() {
				$('#services-block h3').html($(anchor).parent().children('h3').eq(0).html()).fadeIn('slow');
			});
			$('#services-block p').fadeOut('slow', function() {
				$(this).html($(anchor).parent().children('p').eq(0).html()).fadeIn('slow');
			});
		}
		img.src = this.href;
		return(false);
	});
	
	$("#dot-links a").click(function () {
		$(this).parent().siblings().removeClass('sel');
		$(this).parent().addClass('sel');
	 });
	 
	 if($('#dot-links a').length) {
		window.galleryTimer = window.setTimeout(animateGallery, 10000);
	 }
});

function animateGallery() {
	var next = $('#dot-links li.sel').next();
	if(!next.length) {
		next = $('#dot-links li:first');
	}
	next.children('a').eq(0).click();
}






