/***********************************************************************************************************************
DOCUMENT: includes/javascript.js
DEVELOPED BY: Ryan Stemkoski
COMPANY: Zipline Interactive
EMAIL: ryan@gozipline.com
PHONE: 509-321-2849
DATE: 3/26/2009
UPDATED: 3/25/2010
DESCRIPTION: This is the JavaScript required to create the accordion style menu.  Requires jQuery library
NOTE: Because of a bug in jQuery with IE8 we had to add an IE stylesheet hack to get the system to work in all browsers. I hate hacks but had no choice :(.
************************************************************************************************************************/
$(document).ready(function() {

    //ACCORDION BUTTON ACTION (ON CLICK DO THE FOLLOWING)
    $('.accordionButton').click(function() {

        //REMOVE THE ON CLASS FROM ALL BUTTONS
        $('.accordionButton').removeClass('on');

        //NO MATTER WHAT WE CLOSE ALL OPEN SLIDES
        $('.accordionContent').slideUp('normal');

        //IF THE NEXT SLIDE WASN'T OPEN THEN OPEN IT
        if ($(this).next().is(':hidden') == true) {

            //ADD THE ON CLASS TO THE BUTTON
            $(this).addClass('on');

            //OPEN THE SLIDE
            $(this).next().slideDown('normal');
        }

    });
    //ACCORDION BUTTON ACTION (ON CLICK DO THE FOLLOWING)
    $('.accordionButtonBranch').click(function() {

        //REMOVE THE ON CLASS FROM ALL BUTTONS
        $('.accordionButtonBranch').removeClass('onBranch');

        //NO MATTER WHAT WE CLOSE ALL OPEN SLIDES
        $('.accordionContentBranch').slideUp('normal');

        //IF THE NEXT SLIDE WASN'T OPEN THEN OPEN IT
        if ($(this).next().is(':hidden') == true) {

            //ADD THE ON CLASS TO THE BUTTON
            $(this).addClass('onBranch');

            //OPEN THE SLIDE
            $(this).next().slideDown('normal');
            try{
                if (document.getElementById("call-branch-form").innerHTML != "")
                    document.getElementById("branch-form-place").innerHTML = document.getElementById("call-branch-form").innerHTML;
                document.getElementById("call-branch-form").innerHTML = "";
            }
            catch (e) {}
            try{            
                if (document.getElementById("call-garage-form").innerHTML != "")
                    document.getElementById("garage-form-place").innerHTML = document.getElementById("call-garage-form").innerHTML;
                document.getElementById("call-garage-form").innerHTML = "";
            }
            catch (e) {}
        }
        else {
            try {
                document.getElementById("call-branch-form").innerHTML = document.getElementById("branch-form-place").innerHTML;
            }
            catch(e){}
            try {
                document.getElementById("call-garage-form").innerHTML = document.getElementById("garage-form-place").innerHTML;
            }
            catch (e) { }
        }
    });


    //ACCORDION BUTTON ACTION (ON CLICK DO THE FOLLOWING)
    $('.Que').click(function() {




        //IF THE NEXT SLIDE WASN'T OPEN THEN OPEN IT
        if ($(this).hasClass('onQ1') == false) {

            //ADD THE ON CLASS TO THE BUTTON
            $(this).addClass('onQ1');
            $('.Ans').animate({ "top": "0px" }, 800);
            //OPEN THE SLIDE

            $('.Que2').removeClass('onQ2');
            $('.Ans2').animate({ "top": "210px" }, 800);
        }
        else {

            $('.Ans').animate({ top: -210 }, 800, function() { $('.Que').removeClass('onQ1'); });

        }

    });
    $('.Que2').click(function() {

        //IF THE NEXT SLIDE WASN'T OPEN THEN OPEN IT
        if ($(this).hasClass('onQ2') == false) {

            //ADD THE ON CLASS TO THE BUTTON
            $(this).addClass('onQ2');

            //OPEN THE SLIDE
            $('.Ans2').animate({ "top": "0px" }, 1500);
            $('.Ans').animate({ top: -210 }, 1500, function() { $('.Que').removeClass('onQ1'); });
        }
        else {
            $('.Que2').removeClass('onQ2');
            $('.Ans2').animate({ "top": "210px" }, 1500);
        }


    });
    /*** REMOVE IF MOUSEOVER IS NOT REQUIRED ***/

    //ADDS THE .OVER CLASS FROM THE STYLESHEET ON MOUSEOVER 
    $('.accordionButton').mouseover(function() {
        $(this).addClass('over');

        //ON MOUSEOUT REMOVE THE OVER CLASS
    }).mouseout(function() {
        $(this).removeClass('over');
    });

    /*** END REMOVE IF MOUSEOVER IS NOT REQUIRED ***/


    /********************************************************************************************************************
    CLOSES ALL S ON PAGE LOAD
    ********************************************************************************************************************/
    $('.accordionContent').hide();
    //$('.Ans').hide();

});

