/* Rewritten from moo-tools version by HP on apr 7, 09 */

$(document).ready(
    function(){
	var szNormal = "33%", szSmall = "25%", szFull = "49%";

	var kwickLock = false; /* a semiphor to ensure we don't start a new action during the animation of an old one */
	var kwickCurrentTarget; /* the most recently expanded pane */


var kwicks = $("#kwicks .kwick");

/*make sure that it's displaying in the neutral position to start*/
kwicks.css("width", szNormal);


kwicks.bind("mouseenter", /*set a function to be called on mouseenter for each of our panes */
	    function(event) {
		kwickCurrentTarget = $(this); /*this is now the active pane */
		if (kwickLock == false){ /*check if we are already animating */
		    moveTimer(function(){
			    kwickLock = true; /*set semiphor so no one else starts to animate */
			    kwicks.animate({width: szSmall}, 300); /*shrink all panes */
			    kwickCurrentTarget.animate({width: szFull}, 300, "swing", function(){ /*expand current pane */
				    kwickLock = false; /*when done expanding release semiphore */
				});
		    }, 1550);
		}
	    });

/*set an action to be called when mouse leaves the encapsilating kwicks container*/
$("#kwicks").bind("mouseleave", 
	    function(event) {
		      if (kwickLock == false){ /*check & set up the semiphor */
			  kwickLock = true;
			  kwickCurrentTarget.animate({width: szNormal}, 200); /*shrink the active pane faster so we don't get an overflow*/
			  kwicks.animate({width: szNormal}, 400, "swing", function(){ /*grow the other panes */
				  kwickLock = false; /*release semiphor*/
			      });
		}

	    });
    }); /*close document.ready */

function oneshot() { 
    var timer; 
    return function( fun, time ) { 
        clearTimeout( timer ); 
        timer = setTimeout( fun, time ); 
    }; 
}

var moveTimer = oneshot();


