﻿

     var closeSpeed = 700;
     var openSpeed = 700;
     var baseLeft = true;
     var baseRight = false;
     var locked = false;
    
    (function( $ ){
        $.fn.gtaccordion = function() {
            
            return this.each(function(){

                $(this).click(function() {
                    if ($(this).parents(".baseRight").length > 0) {
                        if (!locked) {
                            locked = true;
                            $(".forceOpen").removeClass("forceOpen");
                            go($(this));
                        }
                        $(".panel.hidden").show(100);
                    } 
                    if ($(this).parents(".baseLeft").length > 0) {
                        if ($("#flashcontent_html5").length > 0) {
                            if ($("#flashcontent_html5").hasClass("hidden")) {
                                $("#flashcontent_html5").removeClass("hidden");
                            }
                            else {
                                $("#flashcontent_html5").addClass("hidden");
                            }
                        }
                    }   
                });
                               
            });   
            
        };
    })( jQuery );
    
    function go(Object, removeForceOpen) {
            
        var isactive = false;
        var isBaseLeft = false;
        
        if (removeForceOpen){
            $(".forceOpen").removeClass("forceOpen");
        }
        
        var toOpen = Object.parents(".panel");
        var toClose = $(".panel.active:not(.forceOpen)");
        
        if (toOpen.parents(".baseLeft").length > 0) {
            isBaseLeft = true;
        }
        
        var openWidth = toOpen.find(".content").outerWidth();
        if (isBaseLeft) {
            openWidth = openWidth + 24;
        }
        
        if (toOpen.hasClass("active")) {
            isactive = true;
        }
        
        if (toClose.length > 0) {
        
            toClose.animate(
                { width: '24' }, // what we are animating
                {
                duration: closeSpeed, // how fast we are animating
                easing: 'easeInOutQuad', // the type of easing
                complete: function() { // the callback
                    toClose.removeClass("active");
                    if (!isactive) {
                        toOpen.addClass("active");
                        toOpen.animate(
                            { width: openWidth }, // what we are animating
                            {
                            duration: openSpeed, // how fast we are animating
                            easing: 'easeInOutQuad', // the type of easing
                            complete: function() {
                                locked = false;
                            } 
                        }); 
                    }
                    else {
                        locked = false;
                    }
                }
            });
        }
        else {
            toOpen.addClass("active")
            toOpen.animate(
                { width: openWidth }, // what we are animating
                {
                duration: openSpeed, // how fast we are animating
                easing: 'easeInOutQuad', // the type of easing
                complete: function() { // the callback
                    locked = false;
                }
            }); 
        }
    }
