Category according clickable carrot rotation on active category

So I’m just a nuby on using js and website design in general but doing my best to figure this thing all out.
Currently I have a line of js that is now not working properly:

<script type="text/javascript">

        var currentWindowLocation = window.location.pathname;
        var currentWindowProtocol = window.location.protocol;
        var currentHomePage = '/';
        if(currentWindowLocation != currentHomePage && currentWindowProtocol != 'https:'){
            $(".Content").append('<a href="#TOP" class="TopLink">Back to Top</a>');
        // add parent class to left hand nav for styling and show after styling is done
        $('.Left .category-list li:has(> ul)').addClass('parent');
        $('.Left .category-list li:has(> ul)').prepend('<img class="AccordianCarrot" src="/product_images/uploaded_images/AccordianCarrot.png" />');
        $('.Left .category-list > li').show();
        //Hiding SubCategory lists
        $(".Left .category-list .parent ul").hide();

        //Setting Current Category to a Window Var
        window.topLevelCat = $('#CategoryBreadcrumb li:eq(1)').text() + "";
        //window.currentSubCat = $('#CategoryBreadcrumb li:eq(2)').text() + "";

        window.currentSubCat = $('#CategoryBreadcrumb li');

        //Going Through Each Top Level li and checking to see if it is the current category
        var firstCat = true;
        $('.Left #CategoryList>ul>li').each(function(){
            //Checking to see the current category matches this li's first anchor
            if(window.topLevelCat.indexOf(decodeURIComponent($('a:eq(0)',this).html()).replace('&amp;','&')) >= 0){
                //Expand the SubMenu
                //Applying the pink class to the main cat anchor
                //Looping through each subcat li and checking to see if it's the current subcat
                for(var i = 1; i < window.currentSubCat.length; i++){
                        //If the current li is the subcat
                        //console.log("pre if Current: " + $(window.currentSubCat[i]).text());
                        //console.log("pre if link: " + decodeURIComponent($('a',this).html()).replace('&amp;','&'));
                        var rgx = new RegExp(decodeURIComponent($('a',this).html()).replace('&amp;','&'),"gi");
                        if($(window.currentSubCat[i]).text().indexOf(decodeURIComponent($('a',this).html()).replace('&amp;','&')) >= 0){
                            //console.log("in if Current: " + $(window.currentSubCat[i]).text());
                            //console.log("in if link: " + decodeURIComponent($('a',this).html()).replace('&amp;','&'));
        //rotate carrot for current cat.
        $('.Left .onCatLink > .AccordianCarrot').rotate(90);
        $('.Left .onCatLink > .AccordianCarrot').addClass('rotated');

        $('.Left .AccordianCarrot').click(function(){
            $(this).parent().find('> ul').slideToggle();
            var temp = $(this);


If the text in the menu is selected the sub cats close then open and then the carrot is not rotated down it returns to original position. Original position is pointed to the Cat Text showing there are subs with in it, and when click the arrow points downward to show the cat has been expanded.
Could anyone help me out with this??