/** 
 * Cross-site Slider JS
 *
 * This javascript snippet powers the IMO Cross-site slider, which is a menu that
 * links users to other IMO properties.
 * 
 * Author: Aaron Baker
 * Version: 1.4
 * Created: 2009/03/01 
 * Updated 2009/04/09 by Jacob Angel 
 */

$(document).ready(function(){
	jQuery.fn.closeAllSlider = function(speed, easing, callback) {
		//The follow loop checks to see if any slider is already open, if it is, it closes it.
		$('.cross_site_slider').each(function(i){
			if (parseInt($(this).css('marginTop')) > 0)
			{				
				otherH = 15 + $(this).height() + parseInt($(this).css('paddingTop')) + parseInt($(this).css('paddingBottom'));
				$(this).animate({marginTop: -otherH}, speed, easing, callback);	  
			}			
		});	
	};

	jQuery.fn.slideToggle = function(speed, easing, callback) {
		/*This function animates the sliding menus*/
		//h and otherH measure the height of a slider.  The height is how far a slider must be move before it disappears.
		var h = 15 + this.height() + parseInt(this.css('paddingTop')) + parseInt(this.css('paddingBottom'));		
		var otherH;
				
		//The follow loop checks to see if any slider is already open, if it is, it closes it.
		$('.cross_site_slider').each(function(i){
				
			if (parseInt($(this).css('marginTop')) > 0)
			{				
				otherH = 15 + $(this).height() + parseInt($(this).css('paddingTop')) + parseInt($(this).css('paddingBottom'));
				$(this).animate({marginTop: -otherH}, speed, easing, callback);	  
			}			
		});	
			
	  	//This if check to see if the clicked on slider is not open.  If it is not, the slider opens.
		if (parseInt(this.css('marginTop')) < 0)
		{
			return this.animate({marginTop: 19}, speed, easing, callback);	  
		}
		else {
			return false;
		}
	};

	//This var holds the 4 sliders that will be animated.
	var cross_site_sliders = $('.cross_site_slider');
	var sliderHeight = 0;
	
	cross_site_sliders.each(function(i){
	
        sliderHeight = $(this).height();

        	
		$(this).css("margin-top",sliderHeight * -1);
		
	});
	
    
    var totalSliderOffset = 1;
    var sliderWidth = 0;
    
	//The 4 links in the nav bar each have a corresponding slider
	//When a link is clicked on, the corresponding slide is moved.
	$('.nav_slide_link').each(function(i){

	
		$(this).blur(function(){	
			setTimeout("jQuery.fn.closeAllSlider()",100);		
		});
		
		$(this).click(function(){
			$(cross_site_sliders[i]).slideToggle();
		});
		
		
		totalSliderOffset = sliderWidth + totalSliderOffset; 	
		sliderWidth = $(this).parent().width() + 22;
		
     		
		$(cross_site_sliders[i]).css("margin-left",totalSliderOffset);
		//$(cross_site_sliders[i]).css("left","400px");
			
		
	});	
 });
