/***********************************************************************************************************************
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 () {

    if (!$.browser.msie) {

        //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');
            }

        });


        /*** 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');
        });

        //ADDS THE .OVER CLASS FROM THE STYLESHEET ON MOUSEOVER 
        $('.accordionButtonNoSlide').mouseover(function () {
            $(this).addClass('over');

            //ON MOUSEOUT REMOVE THE OVER CLASS
        }).mouseout(function () {
            $(this).removeClass('over');
        });

        /*** END REMOVE IF MOUSEOVER IS NOT REQUIRED ***/

        var loadedtab = '';
        if ($('#ctl00_carcrashmenubutton').hasClass('tabgreen')) {
            loadedtab = '#ctl00_carcrashmenubutton';
        }
        if ($('#ctl00_whiplashinjurybutton').hasClass('tabgreen')) {
            loadedtab = '#ctl00_whiplashinjurybutton';
        }
        if ($('#ctl00_injurycompensationbutton').hasClass('tabgreen')) {
            loadedtab = '#ctl00_injurycompensationbutton';
        }
        if ($('#ctl00_nowinnofeebutton').hasClass('tabgreen')) {
            loadedtab = '#ctl00_nowinnofeebutton';
        }
        if ($('#ctl00_howmuchbutton').hasClass('tabgreen')) {
            loadedtab = '#ctl00_howmuchbutton';
        }

        /*** CAR CRASH MENU BUTTON AND SUBMENU MOUSE EVENTS START ***/
        $('#ctl00_carcrashmenubutton').mouseover(function () {

            if (loadedtab != '#ctl00_carcrashmenubutton') {
                $(loadedtab).removeClass('tabgreen');
                $(loadedtab).addClass('tabblue');
            }

            $(this).removeClass('tabblue');
            $(this).addClass('tabgreen');
            $('#ctl00_carcrashsubmenu').show();
            $('#imgcarcrashsubmenu').attr("src", '/images/submenu/05.jpg');
            $('#carcrashsubmenutext').html('Get your compensation claim started right here with Car Crash Claims');

        }).mouseout(function () {
            $('#ctl00_carcrashsubmenu').hide();

            if (loadedtab != '#ctl00_carcrashmenubutton') {
                $(this).removeClass('tabgreen');
                $(this).addClass('tabblue');

                $(loadedtab).removeClass('tabblue');
                $(loadedtab).addClass('tabgreen');
            }

        });


        $('#ctl00_carcrashsubmenu').mouseover(function () {
            if (loadedtab != '#ctl00_carcrashmenubutton') {
                $(loadedtab).removeClass('tabgreen');
                $(loadedtab).addClass('tabblue');
            }

            $('#ctl00_carcrashmenubutton').removeClass('tabblue');
            $('#ctl00_carcrashmenubutton').addClass('tabgreen');
            $('#ctl00_carcrashsubmenu').show();

        }).mouseout(function () { //changed to onmouseleave
            $('#ctl00_carcrashsubmenu').hide();

            if (loadedtab != '#ctl00_carcrashmenubutton') {
                $('#ctl00_carcrashmenubutton').removeClass('tabgreen');
                $('#ctl00_carcrashmenubutton').addClass('tabblue');

                $(loadedtab).removeClass('tabblue');
                $(loadedtab).addClass('tabgreen');
            }
        });

        /*** CAR CRASH MENU BUTTON AND SUBMENU MOUSE EVENTS END ***/

        /*** WHIPLASH INJURY MENU BUTTON AND SUBMENU MOUSE EVENTS START ***/
        $('#ctl00_whiplashinjurybutton').mouseover(function () {

            if (loadedtab != '#ctl00_whiplashinjurybutton') {
                $(loadedtab).removeClass('tabgreen');
                $(loadedtab).addClass('tabblue');
            }

            $(this).removeClass('tabblue');
            $(this).addClass('tabgreen');
            $('#ctl00_whiplashinjurysubmenu').show();
            $('#imgwhiplashinjurysubmenu').attr("src", '/images/submenu/11.jpg');
            $('#whiplashinjurysubmenutext').html('We\'ll help you claim maximum compensation if you suffer whiplash');

        }).mouseout(function () {
            $('#ctl00_whiplashinjurysubmenu').hide();

            if (loadedtab != '#ctl00_whiplashinjurybutton') {
                $(this).removeClass('tabgreen');
                $(this).addClass('tabblue');

                $(loadedtab).removeClass('tabblue');
                $(loadedtab).addClass('tabgreen');
            }
        });


        $('#ctl00_whiplashinjurysubmenu').mouseover(function () {
            if (loadedtab != '#ctl00_whiplashinjurybutton') {
                $(loadedtab).removeClass('tabgreen');
                $(loadedtab).addClass('tabblue');
            }

            $('#ctl00_whiplashinjurybutton').removeClass('tabblue');
            $('#ctl00_whiplashinjurybutton').addClass('tabgreen');
            $('#ctl00_whiplashinjurysubmenu').show();

        }).mouseout(function () {
            $('#ctl00_whiplashinjurysubmenu').hide();

            if (loadedtab != '#ctl00_whiplashinjurybutton') {
                $('#ctl00_whiplashinjurybutton').removeClass('tabgreen');
                $('#ctl00_whiplashinjurybutton').addClass('tabblue');

                $(loadedtab).removeClass('tabblue');
                $(loadedtab).addClass('tabgreen');
            }
        });

        /*** WHIPLASH INJURY MENU BUTTON AND SUBMENU MOUSE EVENTS END ***/

        /*** INJURY COMPENSATION MENU BUTTON AND SUBMENU MOUSE EVENTS START ***/
        $('#ctl00_injurycompensationbutton').mouseover(function () {

            if (loadedtab != '#ctl00_injurycompensationbutton') {
                $(loadedtab).removeClass('tabgreen');
                $(loadedtab).addClass('tabblue');
            }

            $(this).removeClass('tabblue');
            $(this).addClass('tabgreen');
            $('#ctl00_injurycompensationsubmenu').show();
            $('#imginjurycompensationsubmenu').attr("src", '/images/submenu/13.jpg');
            $('#injurycompensationsubmenutext').html('Car Crash Claims\' legal experts will always claim maximum possible compensation for you');

        }).mouseout(function () {
            $('#ctl00_injurycompensationsubmenu').hide();

            if (loadedtab != '#ctl00_injurycompensationbutton') {
                $(this).removeClass('tabgreen');
                $(this).addClass('tabblue');

                $(loadedtab).removeClass('tabblue');
                $(loadedtab).addClass('tabgreen');
            }
        });


        $('#ctl00_injurycompensationsubmenu').mouseover(function () {
            if (loadedtab != '#ctl00_injurycompensationbutton') {
                $(loadedtab).removeClass('tabgreen');
                $(loadedtab).addClass('tabblue');
            }

            $('#ctl00_injurycompensationbutton').removeClass('tabblue');
            $('#ctl00_injurycompensationbutton').addClass('tabgreen');
            $('#ctl00_injurycompensationsubmenu').show();

        }).mouseout(function () {
            $('#ctl00_injurycompensationsubmenu').hide();

            if (loadedtab != '#ctl00_injurycompensationbutton') {
                $('#ctl00_injurycompensationbutton').removeClass('tabgreen');
                $('#ctl00_injurycompensationbutton').addClass('tabblue');

                $(loadedtab).removeClass('tabblue');
                $(loadedtab).addClass('tabgreen');
            }
        });

        /*** INJURY COMPENSATION MENU BUTTON AND SUBMENU MOUSE EVENTS END ***/

        /*** NO WIN NO FEE MENU BUTTON AND SUBMENU MOUSE EVENTS START ***/
        $('#ctl00_nowinnofeebutton').mouseover(function () {

            if (loadedtab != '#ctl00_nowinnofeebutton') {
                $(loadedtab).removeClass('tabgreen');
                $(loadedtab).addClass('tabblue');
            }

            $(this).removeClass('tabblue');
            $(this).addClass('tabgreen');
            $('#ctl00_nowinnofeesubmenu').show();
            $('#imgnowinnofeesubmenu').attr("src", '/images/submenu/16.jpg');
            $('#nowinnofeesubmenutext').html('What \'no win no fee\' means, how it works, and how it can help you to claim compensation');

        }).mouseout(function () {
            $('#ctl00_nowinnofeesubmenu').hide();

            if (loadedtab != '#ctl00_nowinnofeebutton') {
                $(this).removeClass('tabgreen');
                $(this).addClass('tabblue');

                $(loadedtab).removeClass('tabblue');
                $(loadedtab).addClass('tabgreen');
            }
        });


        $('#ctl00_nowinnofeesubmenu').mouseover(function () {
            if (loadedtab != '#ctl00_nowinnofeebutton') {
                $(loadedtab).removeClass('tabgreen');
                $(loadedtab).addClass('tabblue');
            }

            $('#ctl00_nowinnofeebutton').removeClass('tabblue');
            $('#ctl00_nowinnofeebutton').addClass('tabgreen');
            $('#ctl00_nowinnofeesubmenu').show();

        }).mouseout(function () {
            $('#ctl00_nowinnofeesubmenu').hide();

            if (loadedtab != '#ctl00_nowinnofeebutton') {
                $('#ctl00_nowinnofeebutton').removeClass('tabgreen');
                $('#ctl00_nowinnofeebutton').addClass('tabblue');

                $(loadedtab).removeClass('tabblue');
                $(loadedtab).addClass('tabgreen');
            }
        });

        /*** NO WIN NO FEE MENU BUTTON AND SUBMENU MOUSE EVENTS END ***/

        /*** HOW MUCH MENU BUTTON AND SUBMENU MOUSE EVENTS START ***/
        $('#ctl00_howmuchbutton').mouseover(function () {

            if (loadedtab != '#ctl00_howmuchbutton') {
                $(loadedtab).removeClass('tabgreen');
                $(loadedtab).addClass('tabblue');
            }

            $(this).removeClass('tabblue');
            $(this).addClass('tabgreen');
            $('#ctl00_howmuchsubmenu').show();
            $('#imghowmuchsubmenu').attr("src", '/images/submenu/21.jpg');
            $('#howmuchsubmenutext').html('Take 30 seconds to find out! We\'ll even send you a text ');

        }).mouseout(function () {
            $('#ctl00_howmuchsubmenu').hide();

            if (loadedtab != '#ctl00_howmuchbutton') {
                $(this).removeClass('tabgreen');
                $(this).addClass('tabblue');

                $(loadedtab).removeClass('tabblue');
                $(loadedtab).addClass('tabgreen');
            }
        });


        $('#ctl00_howmuchsubmenu').mouseover(function () {
            if (loadedtab != '#ctl00_howmuchbutton') {
                $(loadedtab).removeClass('tabgreen');
                $(loadedtab).addClass('tabblue');
            }

            $('#ctl00_howmuchbutton').removeClass('tabblue');
            $('#ctl00_howmuchbutton').addClass('tabgreen');
            $('#ctl00_howmuchsubmenu').show();

        }).mouseout(function () {
            $('#ctl00_howmuchsubmenu').hide();

            if (loadedtab != '#ctl00_howmuchbutton') {
                $('#ctl00_howmuchbutton').removeClass('tabgreen');
                $('#ctl00_howmuchbutton').addClass('tabblue');

                $(loadedtab).removeClass('tabblue');
                $(loadedtab).addClass('tabgreen');
            }
        });

        /*** HOW MUCH MENU BUTTON AND SUBMENU MOUSE EVENTS END ***/

        /*** HOOK UP IMAGE SWAP IN SUBMENU START ***/

        var cache = [];

        function preloadsubmenuimages() {
            var args_len = arguments.length;
            for (var i = args_len; i--; ) {
                var cacheImage = document.createElement('img');
                cacheImage.src = arguments[i];
                cache.push(cacheImage);
            }
        }

        function submenulinkover(submenulinkid, imgsubmenuid, submenulinkimagepath, submenutextid, submenutext) {
            $(imgsubmenuid).attr("src", submenulinkimagepath);
            $(submenulinkid).css('font-weight', 'bold');
            $(submenutextid).html(submenutext);
        }

        function submenulinkout(submenulinkid) {
            $(submenulinkid).css('font-weight', 'normal');
        }

        $('#submenulink01').mouseover(function () {
            submenulinkover(this, '#imgcarcrashsubmenu', '/images/submenu/05.jpg', '#carcrashsubmenutext', 'Get your compensation claim started right here with Car Crash Claims');
        }).mouseout(function () {
            submenulinkout(this);
        });


        $('#submenulink02').mouseover(function () {
            submenulinkover(this, '#imgcarcrashsubmenu', '/images/submenu/03.jpg', '#carcrashsubmenutext', 'Find out in as little as 30 seconds how much compensation you could claim');
        }).mouseout(function () {
            submenulinkout(this);
        });

        $('#submenulink03').mouseover(function () {
            submenulinkover(this, '#imgcarcrashsubmenu', '/images/submenu/04.jpg', '#carcrashsubmenutext', 'We take the hassle out of car repair after you\'ve had a crash');
        }).mouseout(function () {
            submenulinkout(this);
        });

        $('#submenulink04').mouseover(function () {
            submenulinkover(this, '#imgcarcrashsubmenu', '/images/submenu/02.jpg', '#carcrashsubmenutext', 'Speak to us first if you\'ve been injured in a car crash');
        }).mouseout(function () {
            submenulinkout(this);
        });

        $('#submenulink05').mouseover(function () {
            submenulinkover(this, '#imgcarcrashsubmenu', '/images/submenu/01.jpg', '#carcrashsubmenutext', 'Claim maximum compensation if you\'ve been injured in a car crash');
        }).mouseout(function () {
            submenulinkout(this);
        });

        $('#submenulink06').mouseover(function () {
            submenulinkover(this, '#imgwhiplashinjurysubmenu', '/images/submenu/07.jpg', '#whiplashinjurysubmenutext', 'Claim compensation here if you\'ve suffered a head injury');
        }).mouseout(function () {
            submenulinkout(this);
        });

        $('#submenulink07').mouseover(function () {
            submenulinkover(this, '#imgwhiplashinjurysubmenu', '/images/submenu/08.jpg', '#whiplashinjurysubmenutext', 'Injured your knee? Speak to Car Crash Claims');
        }).mouseout(function () {
            submenulinkout(this);
        });

        $('#submenulink08').mouseover(function () {
            submenulinkover(this, '#imgwhiplashinjurysubmenu', '/images/submenu/12.jpg', '#whiplashinjurysubmenutext', 'If you\'ve injured your wrist, click here to claim compensation');
        }).mouseout(function () {
            submenulinkout(this);
        });

        $('#submenulink09').mouseover(function () {
            submenulinkover(this, '#imgwhiplashinjurysubmenu', '/images/submenu/11.jpg', '#whiplashinjurysubmenutext', 'We\'ll help you claim maximum compensation if you suffer whiplash');
        }).mouseout(function () {
            submenulinkout(this);
        });

        $('#submenulink10').mouseover(function () {
            submenulinkover(this, '#imgwhiplashinjurysubmenu', '/images/submenu/06.jpg', '#whiplashinjurysubmenutext', 'Talk to Car Crash Claims to claim compensation if you\'ve hurt your back');
        }).mouseout(function () {
            submenulinkout(this);
        });

        $('#submenulink11').mouseover(function () {
            submenulinkover(this, '#imgwhiplashinjurysubmenu', '/images/submenu/09.jpg', '#whiplashinjurysubmenutext', 'Click here to claim compensation for a leg injury');
        }).mouseout(function () {
            submenulinkout(this);
        });

        $('#submenulink12').mouseover(function () {
            submenulinkover(this, '#imgwhiplashinjurysubmenu', '/images/submenu/10.jpg', '#whiplashinjurysubmenutext', 'If you\'ve been unlucky enough to suffer a spine injury, we\'ll help you claim compensation');
        }).mouseout(function () {
            submenulinkout(this);
        });

        $('#submenulink13').mouseover(function () {
            submenulinkover(this, '#imginjurycompensationsubmenu', '/images/submenu/13.jpg', '#injurycompensationsubmenutext', 'Car Crash Claims\' legal experts will always claim maximum possible compensation for you');
        }).mouseout(function () {
            submenulinkout(this);
        });

        $('#submenulink14').mouseover(function () {
            submenulinkover(this, '#imginjurycompensationsubmenu', '/images/submenu/14.jpg', '#injurycompensationsubmenutext', 'As long as your accident wasn\'t your fault, we\'ll guide you through every step of the claims process');
        }).mouseout(function () {
            submenulinkout(this);
        });

        $('#submenulink15').mouseover(function () {
            submenulinkover(this, '#imginjurycompensationsubmenu', '/images/submenu/15.jpg', '#injurycompensationsubmenutext', 'If you\'ve been injured, look here first to see what you should do');
        }).mouseout(function () {
            submenulinkout(this);
        });

        $('#submenulink16').mouseover(function () {
            submenulinkover(this, '#imgnowinnofeesubmenu', '/images/submenu/16.jpg', '#nowinnofeesubmenutext', 'What \'no win no fee\' means, how it works, and how it can help you to claim compensation');
        }).mouseout(function () {
            submenulinkout(this);
        });

        $('#submenulink17').mouseover(function () {
            submenulinkover(this, '#imgnowinnofeesubmenu', '/images/submenu/18.jpg', '#nowinnofeesubmenutext', 'Our solicitors will always strive to win you the maximum compensation amount they can');
        }).mouseout(function () {
            submenulinkout(this);
        });

        $('#submenulink18').mouseover(function () {
            submenulinkover(this, '#imgnowinnofeesubmenu', '/images/submenu/19.jpg', '#nowinnofeesubmenutext', 'You don\'t win your case, you have nothing to pay. Simple as that.');
        }).mouseout(function () {
            submenulinkout(this);
        });

        $('#submenulink19').mouseover(function () {
            submenulinkover(this, '#imgnowinnofeesubmenu', '/images/submenu/17.jpg', '#nowinnofeesubmenutext', 'No win, no fee, no risk. Why claiming with us willgive you a good night\'s sleep');
        }).mouseout(function () {
            submenulinkout(this);
        });

        $('#submenulink20').mouseover(function () {
            submenulinkover(this, '#imgnowinnofeesubmenu', '/images/submenu/20.jpg', '#nowinnofeesubmenutext', 'Some companies are only \'no win no fee\' some of the time. Not us.');
        }).mouseout(function () {
            submenulinkout(this);
        });

        $('#submenulink21').mouseover(function () {
            submenulinkover(this, '#imghowmuchsubmenu', '/images/submenu/21.jpg', '#howmuchsubmenutext', 'Take 30 seconds to find out! We\'ll even send you a text');
        }).mouseout(function () {
            submenulinkout(this);
        });

        $('#submenulink22').mouseover(function () {
            submenulinkover(this, '#imghowmuchsubmenu', '/images/submenu/24.jpg', '#howmuchsubmenutext', 'If you do lose your case, you won\'t be out of pocket by one penny');
        }).mouseout(function () {
            submenulinkout(this);
        });

        $('#submenulink23').mouseover(function () {
            submenulinkover(this, '#imghowmuchsubmenu', '/images/submenu/23.jpg', '#howmuchsubmenutext', 'Get your car repaired with Car Crash Claims and keep your NCB intact');
        }).mouseout(function () {
            submenulinkout(this);
        });

        $('#submenulink24').mouseover(function () {
            submenulinkover(this, '#imghowmuchsubmenu', '/images/submenu/22.jpg', '#howmuchsubmenutext', 'You don\'t pay a penny towards your excess when we repair your car ');
        }).mouseout(function () {
            submenulinkout(this);
        });

        /*** HOOK UP IMAGE SWAP IN SUBMENU END ***/


        /********************************************************************************************************************
        CLOSES ALL S ON PAGE LOAD
        ********************************************************************************************************************/
        $('.accordionContent').hide();
        $('#ctl00_carcrashsubmenu').hide();
        $('#ctl00_whiplashinjurysubmenu').hide();
        $('#ctl00_injurycompensationsubmenu').hide();
        $('#ctl00_nowinnofeesubmenu').hide();
        $('#ctl00_howmuchsubmenu').hide();
        preloadsubmenuimages('/images/submenu/01.jpg', '/images/submenu/02.jpg', '/images/submenu/03.jpg', '/images/submenu/04.jpg', '/images/submenu/05jpg', '/images/submenu/06.jpg', '/images/submenu/07.jpg', '/images/submenu/08.jpg', '/images/submenu/09.jpg', '/images/submenu/10.jpg', '/images/submenu/11.jpg', '/images/submenu/12.jpg', '/images/submenu/13.jpg', '/images/submenu/14.jpg', '/images/submenu/15.jpg', '/images/submenu/16.jpg', '/images/submenu/17.jpg', '/images/submenu/18.jpg', '/images/submenu/19.jpg', '/images/submenu/20.jpg', '/images/submenu/21.jpg', '/images/submenu/22.jpg', '/images/submenu/23.jpg', '/images/submenu/24.jpg');

        /* SET LEFT NAV MENU START */
        var locpath = window.location.pathname;
        var currentareaarray = locpath.split('/');
        var currentarea = currentareaarray[1];

        if (currentarea != '') {
            //ADD THE ON CLASS TO THE BUTTON
            $('#' + currentarea).addClass('on');

            //OPEN THE SLIDE
            $('#' + currentarea).next().slideDown(0);
        }
        /* END */

    }
});

