﻿

/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 * Global Landing Page Accordion
========================================================================================== */
/**
 * @namespace glAccordion
 */
var glAccordion = glAccordion || {};

// REQUIRES JQUERY PRELOADED
$(document).ready(function(){
	lastBlock = $("#end_left"); // default selected block
	leftEnd = $("#end_left");
	rightEnd = $("#end_right");
    maxWidth = 355;
    minWidth = 80;	

    $(".accordion ul li a").hover(
		function(){
			//swap the background on the current mouse over before the expand anim begins
			glAccordion.swapBkg(this, 'mouseOver');
			//animate the lastblock out, oncomplete: swap backgrounds
			$(lastBlock).animate({width: minWidth+"px"}, { queue:false, duration:10, 
				complete: function(){
					glAccordion.swapBkg(this, 'mouseOut');
				}
			});
			//animate current mouseover in
			$(this).animate({width: maxWidth+"px"}, { queue:false, duration:10, 
				complete: function(){
					// redundant background swap, incase mouseout oncomplete callback hasn't fired yet
					glAccordion.swapBkg(this, 'mouseOver');
				}
			});
			// set the last block to the one just opened, so we can close it later
			lastBlock = this; 
		}
    );
	
	
});

// swaps out backgrounds for elements on mouse over and mouse out
glAccordion.swapBkg = function(e, type) {
	switch(type) {
		case "mouseOver":
			// pre, on mouseOver, should have been fired before the animation started
			if($(e).hasClass("right_end")) {
				// right end
				$(e).addClass("right_expanded");
			} else if ($(e).hasClass("end_left")) {
				// left end
				$(e).addClass("left_expanded");
			} else {
				// all others (middle)
				$(e).addClass("expanded");
			}
			break;
		case "mouseOut":
			// post, on mouseOut, should have been fired when the animation is complete
			if($(e).hasClass("right_end")) {
				// right end
				$(e).removeClass("right_expanded");
			} else if ($(e).hasClass("end_left")) {
				// left end
				$(e).removeClass("left_expanded");
			} else {
				// all others (middle)
				$(e).removeClass("expanded");
			}
			break;
		default:
			// default is to do nothing, so...
	}
};

