// JavaScript Document for Terra Communications website effects

$(document).ready(function(){
    $(document).pngFix(); // msie sucks, but lets make png work in version 6, I guessÉ
    
    if ($(".sc_menu").length > 0 ) {
   		//Get our elements for faster access and set overlay width
  		var div = $('div.sc_menu'),
             ul = $('ul.sc_menu'),
        
        // unordered list's left margin
             ulPadding = 15;

  		//Get menu width
  		var divWidth = div.width();

  		//Remove scrollbars
  		div.css({overflow: 'hidden'});

  		//Find last image container
  		var lastLi = ul.find('li:last-child');

  		//When user move mouse over menu
  		div.mousemove(function(e){
    		//As images are loaded ul width increases,
    		//so we recalculate it each time
    		var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;

    		var left = (e.pageX - div.offset().left) * (ulWidth-divWidth) / divWidth;
    		div.scrollLeft(left);
  		});
    }
    
    if ($(".anythingSlider").length > 0) {
    	function formatText(index, panel) {
	  		return "<img src=\"images/slider/blank.png\" alt=\"\" />";
    	}
    
    	$('.anythingSlider').anythingSlider({
        	easing: "easeInOutExpo", 
        	autoPlay: true, 
        	delay: 3000, 
        	startStopped: false, 
        	animationTime: 1200, 
        	hashTags: true, 
        	buildNavigation: true, 
 			pauseOnHover: true, 
 			startText: "Play", 
 			stopText: "Pause", 
 			navigationFormatter: formatText
         });
         
         $("#slide-jump").click(function(){
             $('.anythingSlider').anythingSlider(6);
         });
	}
    
	if ($("#accordion").length > 0 ) { // check for accordion and initialize it if it exists
		$("#accordion").accordion({ header: 'h3', fillSpace: true });
	};
	$(".content").hide(); // must hide content to be faded *after* the accordion is created.

	var winHeight = $(window).height();
	$("#wrapper").css({'min-height' : winHeight}); // want the yellow background to span the current window height

	$("a").click(function(event){
		$(this).blur();	// blurs all links when clicked
	});
		
	$("#nav a").click(function(event){
		var hrefLoc = $(this).attr('href');
		event.preventDefault(); // capture clicks of navigation links so we can do a fancy fade out effect. Evil, I know.
		$("#footer").fadeOut(800);
		$(".content").fadeOut(800);
		
//		$(".content").stop().animate({right:'-960px'}, {queue:false, duration:500, easing: 'easeInOutBack'});
//      fading was deemed prettier than easing. Change css to if you put it back in!

		$(this).delay(1000,function(){
			window.location = hrefLoc; // go to the page that was clicked!
		});
		return false;
	});

	$(this).delay(500,function(){
		//Show the elements
		$(".content").fadeIn(1500);

//		$(".content").stop().animate({right:'-340px'}, {queue:false, duration:1500, easing: 'easeInOutBack'});
//      fading was deemed prettier than easing. Change css to if you put it back in!

    });

	$(this).delay(1600,function(){
		var offset = $(".content-bottom").offset();
		$("#footer").css({'top':offset.top-10});
		$("#footer").slideDown(1000); // nifty footer.
	});
});
