/*	
	MDM 4.0 
	Copyright (c) 2002-2011 Multidmedia Limited (MDM)
	http://www.multidmedia.com

*/


// ----------------------------------- External Page Fade In ----------------------------------- //

$(document).ready(function(){
	$("body").hide().fadeIn(500);
});

// --------------------------------- Question & Answer Expand ---------------------------------- //

$(document).ready(function(){
	$(".q").click(function() {
		$(this).next(".a").slideToggle('slow');
		//Scroll Effect
		var position = $(this).position();
		var target = position.top;
		$('#mainContent').animate({scrollTop:target}, 500);
		//End Scroll
	});
});

// ---------------------------------- Expand Button Sections ----------------------------------- //

$(document).ready(function(){
						   
	$(".hide").hide();
	$(".form li div").hide(); // <-- Hides Validation Divs for Form Inputs
	
	$(".btnExpand").click(function() {
		btnID = this.id;
		$("ul#"+btnID).slideToggle('slow'); // <-- Hidden UL id must match btnExpand id
		//Scroll Effect
		var position = $(this).offset();
		var target = position.top;
		$('#mainContent').animate({scrollTop:target}, 500);
		//End Scroll
	});	
});

// --------------------------------------- Content Group Transitions --------------------------------------- //

$(document).ready(function(){
	$(".ContentBlock").hide(); // Hide ALL Content Groups
	if (location.hash){
		hashval = location.hash.substring(1, location.hash.length);	// Get the Hash Value minus the # Character
		if ( $('#_'+hashval).length ) { // Check if hash value actually exists in doc (Prevent Random Hash Vals)
			activeSection = hashval;
		} else {
			activeSection = $('.ContentMenuLink:first').attr('rel');	
		}
	} else {
		//activeSection = 'Overview';
		activeSection = $('.ContentMenuLink:first').attr('rel');
	}
	$('#ContentContainer').append($('#_'+activeSection)); // Move the pre-activeSection to the bottom of the 'deck'
	$('#_'+activeSection).show();
	$('a[rel='+activeSection+']').addClass("ContentMenuActive");
	
	$('.ContentMenuLink').click(function() {
		if (!$('#_'+activeSection).is(':animated')){ // Only Execute if NOT already animating
			newSection = $(this).attr('rel'); // Get the new Section from the links Rel Value
			$(".ContentMenuActive").removeClass("ContentMenuActive");
			$(this).addClass("ContentMenuActive");
			if(activeSection != newSection){
				$('#_'+activeSection+',#_'+newSection).animate({
				opacity: 'toggle',
				height: 'toggle'
				}, 1000, function(){
					$('#ContentContainer').append($('#_'+activeSection)); // Move the pre-activeSection to the bottom of the 'deck'
					activeSection = newSection; // Set the new Section as the Current Active Section
					
	
				});
			}
		}
	});
});

// --------------------------------------- Main Menu Slide Out/In --------------------------------------- //
$(document).ready(function(){
	menuState = 'Close';
	$('#HeaderLogo,#Header,#MenuBtn').bind('mouseenter click', function(){
		$('#Menu').animate({ height: 125 }, 500 ) ;
		$('#MenuBtn').fadeOut(500);
		menuState = 'Open';
	  });
	  /*$('#Menu').mouseleave(function(){
		  $('#Menu').delay(1000).animate({ height: 0 }, 500 ) 
		  $('#MenuBtn').delay(1000).fadeIn(500);
	  });*/
	});
$(document).mousemove(function(e){
      if(e.pageY > 700 && menuState == 'Open'){
		  $('#Menu').animate({ height: 0 }, 500 ) ;
		  $('#MenuBtn').fadeIn(500);
		  menuState = 'Close';
	  }
  }); 
// --------------------------------------- Custom Defined Functions --------------------------------------- //

function scrollTo(id, section){
	if(section){
		$('a[rel='+section+']').trigger('click');
	}
	/*var test = $("#"+id).position().top;
	alert(test);*/
	
	$("html:not(:animated),body:not(:animated)").animate({scrollTop: $("#"+id).offset().top},'slow');
	/* Changed from posiiton().top to offset().top */
};


