//jQuery addons
$(document).ready(function() {

	// HOVER INFO BOX
	// Moves the hover div info with the mouse cursor
	$(document).mousemove(function(e) {
		width = $("#hover").width();
		$("#hover").css({
			'left': (e.pageX-(width/2))+"px",
			'top': (e.pageY-80)+"px"
		});
	});
	// Does a hover info state for the navigation
	$(".hover").hover(
		function() {
			if ( $("#hover").hasClass("hide") ) {
				$("#hover").removeClass("hide");
			}
			img = $(this).html();
			img = img.replace(/ /g, "_");
			img = img.replace("Hawryshkewich", "Haw");
			email = $(this).attr("rel");
			email = email.replace("SFU", '<span class="eml"></span><span class="r">ac.ufs</span>');
			email = email.replace("@", '<span class="eml"></span>');
			email = email.replace("--", "</b><br/>");
			$("#hover").stop(true,true);
			$("#hover").css('display', 'block');
			$("#hover").html('<img src="content/members/images/'+img+'.jpg" height="50" width="50" alt="'+img+'" /><div class="email"><b>'+email+'</div>');
			$("#hover").fadeTo(100, 0.95);
		},
		function() {
			$("#hover").stop(true,true);
			$("#hover").fadeTo(100, 0)
			$("#hover").css('display','none');
			//$("#hover").html("");
		}
	);
						   
  // Enables blocks of text to be shown and hidden
  $("h3").hover(
    function () {
		  if ($(this).next('.showhide:visible').length > 0 ) {
	        $(this).find('.status:next').html("(click to hide)");
		  } else {
	        $(this).find('.status:next').html("(click to show)");
		  }
    }, 
    function () {
      $(this).find('.status:next').html("(+/-)");
    }
  );
  
  // Image hover fade 
  $(".fade").hover(
	function() {
	  $(this).fadeTo(150, 0.7);
	},
	function() {
	  $(this).fadeTo(150, 1.0);
	}
  );
  
  // Enables the showing and hiding of text elements
  $('.block>h3').click(function() {
	 $(this).next('.showhide').slideToggle(650);	
  }); 
  
  
  // Cycles the thumbnails for the videos
	$(".video_thumb").cycle({
		speed: 750
	});
  $(".video_thumb").click(function() {
		$(this).cycle('pause'); // Pauses cycling when a video is opened
	});
	$("#TB_closeWindowButton").click(function() {
		$(".video_thumb").cycle('resume'); // Resumes cycling when a video is closed
	});
	
});


// Cycle video
$(window).load(function() {
}); 

// Hides the other elements
function raiseHeading(id) {
  $(document).ready(function() {
	if ($("#"+id+"").hasClass("first")){
	} else {
		$(".heading:first").removeClass("first");
		$("#"+id+"").fadeTo(300, 0.1, function() {
	  		$("#"+id+"").insertBefore(".heading:first");
		});
		$("#"+id+"").fadeTo(300, 1.0);
		$("#"+id+"").addClass("first");
	}
  });
}

function raise(id) {
  $(document).ready(function() {
	if ($("#"+id+"").parents(".heading").hasClass("first")){
		if ($("#"+id+"").hasClass("first")){
		} else {
			$(".block:first").removeClass("first");
			$("#"+id+"").fadeTo(300, 0.1, function() {
				$("#"+id+"").insertBefore(".block:first");
			});
			$("#"+id+"").fadeTo(300, 1.0);
			$("#"+id+"").addClass("first");
		}
	} else {
		var headID = $("#"+id+"").parents(".heading").attr("id");
		raiseHeading(headID);
		if ($("#"+id+"").hasClass("first")){
		} else {
			$("#"+headID+" .block:first").removeClass("first");
			$("#"+id+"").fadeTo(300, 0.1, function() {
				$("#"+id+"").insertBefore(".block:first");
			});
			$("#"+id+"").fadeTo(300, 1.0);
			$("#"+id+"").addClass("first");
		}	
	}
  });
  
}
