﻿/* 
Modified by: Ben Wilkinson 
Date: 12/05/2011
Tutorial ref: http://codeblitz.wordpress.com/2009/04/15/jquery-animated-collapsible-list/
*/
$.noConflict();
jQuery(document).ready(function ($) {
    
    //Disable animation in IE (looks crappy)
    var $AnimSpeed = ($.browser.msie) ? null : 'fast';

    //Add hitbox in li's with ul's in them
    $('ul.foldingMenu li:has(ul:has(li))').prepend('<div class="hitboxClosed"></div>');

    //Add event to hitbox
    var $hitbox = $('div.hitboxClosed');

    if ($hitbox != null) {
        $hitbox.click(function (event) {
            if (this == event.target) {
                $(this).removeClass('hitboxClosed').removeClass('hitboxOpen').addClass(
					(!$(this).parent().children("ul").is(':hidden')) ?
						'hitboxClosed' : 'hitboxOpen')

                .parent().children("ul").toggle($AnimSpeed);
            }
            return false;
        })
        .css({ cursor: 'pointer' })
        .parent().children("ul").hide();

        $('ul.foldingMenu li:not(:has(ul))').css({ 'cursor': 'default', 'list-style-image': 'none' });
    }

    //Set highlight colour in menu
    //var path = location.pathname;

    //Set highlight colour in menu and open to the highlight
    //var currentSelection = $("span#categoryProductCurrentSelected").text().trim();
    var currentSelection = $.trim($("span#categoryProductCurrentSelected").text());
    $("div.sideMenu ul.foldingMenu li a:contains('" + currentSelection + "')")
        .filter(function () {
            return $(this).text() === currentSelection;
        })
        .each(function () {
            $(this).addClass('selectedMenuItem');
            $(this).parents().show();

            //change arrows to open
            $(this).parentsUntil('ul.foldingMenu').find('div.hitboxClosed')
                .removeClass('hitboxClosed')
                .addClass('hitboxOpen')
                .parent().children("ul").show();
        });

    //replace select with span
    if (!$.browser.opera) {
        $('select.contactUsEntryDDL').each(function () {
            var title = $(this).attr('title');
            if ($('option:selected', this).val() != '') title = $('option:selected', this).text();
            $(this)
            .css({ 'z-index': 10, 'opacity': 0, '-khtml-appearance': 'none' })
            .after('<span class="contactUsEntryDDL">' + title + '</span>')
            .change(function () {
                val = $('option:selected', this).text();
                $(this).next().text(val);
            })
        });
    };

});

//    function (event) {

//TODO: jQuery images
//Add custom functions
//	$.extend($.fn, {
//		swapClass: function(c1, c2) {
//			var c1Elements = this.filter('.' + c1);
//			this.filter('.' + c2).removeClass(c2).addClass(c1);
//			c1Elements.removeClass(c1).addClass(c2);
//			return this;
//		},
//		replaceClass: function(c1, c2) {
//			return this.filter('.' + c1).removeClass(c1).addClass(c2).end();
//		}
//    });

//TODO: jQuery images
// swap classes for hitarea
//					.find(">.hitarea")
//						.swapClass( CLASSES.collapsableHitarea, CLASSES.expandableHitarea )
//						.swapClass( CLASSES.lastCollapsableHitarea, CLASSES.lastExpandableHitarea )
//					.end()
