//-------------
// GLOBAL VARS
//-------------

// global object
if (!IOM) var IOM = {};

IOM.textSizeCookieName = 'IOMTextSize';
IOM.textSizeStyles = Array('', 'Medium', 'Large');
IOM.slideshowColors = Array('#0C706B', '#995905', '#605677', '#8e301c');
IOM.slideshowCurrColor = 0;

//-----------
// FUNCTIONS
//-----------

IOM.closeLogin = function() {
    $(".memberlogin").removeClass("on");
    $("#memberlogin").fadeOut({ speed: 'fast' });
};

IOM.closeTopicsPanel = function() {
    $("#topics").slideUp("fast", function() {
        $("#explorebtn").removeClass("on").addClass("off");
    });
};

IOM.loadSavedTextSize = function() {
    /* called when page loads, set the text size from cookie */
    IOM.setTextSize(IOM.getSavedTextSize());
}

IOM.toggleTextSize = function(_increase) {
    /* increase/decrease text size. _increase:Bool */

    /*  text sizes:	
    default	= 0 | main.css
    Medium 	= 1 | text_size_m.css
    Large 	= 2 | text_size_l.css */

    var currTextSize = IOM.getSavedTextSize();

    if (_increase === true) {
        /* increase the text size*/
        if (currTextSize < IOM.textSizeStyles.length - 1) {
            IOM.setTextSize(currTextSize + 1);
        }
    }
    else {
        /* decrease the text size */
        if (currTextSize > 0) {
            IOM.setTextSize(currTextSize - 1);
        }
    }
}

IOM.setTextSize = function(_size) {
    /* sets the text size, _size:Int */

    // set the cookie
    IOM.setCookie(IOM.textSizeCookieName, _size, 2);

    // load css file
    IOM.loadTextSizeStyle(_size);
}

IOM.loadTextSizeStyle = function(_size) {
    /* switch stylesheets */

    // disable all 
    $('link[title]').each(function() {
        $(this).attr('disabled', true);
    });

    if (_size > 0) {
        //enable selected
        $('link[title=' + IOM.textSizeStyles[_size] + ']').attr('disabled', false);
    }
}


IOM.getSavedTextSize = function() {
    /* retrieves the current text size from cookie */

    var textSize = IOM.getCookieVal(IOM.textSizeCookieName);
    return (textSize === null) ? 0 : Number(textSize);
}

IOM.setCookie = function(_name, _val, _days) {
    /* set cookie, expects _name:String, _val:String, _days:Int */

    var date = new Date();
    date.setTime(date.getTime() + (_days * 24 * 60 * 60 * 1000));

    var textSizeCookie = _name + '=' +
							  escape(_val) +
							'; expires=' + date.toGMTString();
    //'; path="/"'+
    //'; domain=""'+
    //'; secure=""';

    document.cookie = textSizeCookie;
}

IOM.getCookieVal = function(_name) {
    /* get the value from cookie, expects _name:String*/

    // IOMTextSize=1; IOMTextSize2=2		
    var cookie = document.cookie;
    var prefix = IOM.textSizeCookieName + '='
    var startAt = null;
    var endAt = null;

    if (cookie.indexOf(prefix) == -1) {
        // cookie doesn't exist
        return null;
    }
    else {
        startAt = cookie.indexOf(prefix) + prefix.length;
        endAt = cookie.indexOf(';', startAt);

        if (endAt == -1) {
            endAt = cookie.length;
        }

        return unescape(cookie.substring(startAt, endAt));
    }
}

IOM.updatedSlideHeight = function(_slide) {
    if (_slide.is(':visible')) {
        var height = 0;
        $('ul li', _slide).each(function() {
            if ($(this).height() > height) {
                height = $(this).height();
            }
        });
        $('ul li', _slide).css('height', height);
        _slide.parent().animate({ height: _slide.height() }, 'fast');
    }
}

IOM.updatedSlideNav1 = function(curr, next, opts) {

    var currSlide = opts.currSlide + 1;
    var totalSlides = opts.slideCount;

    if (currSlide == totalSlides) { $('#s1forward').removeClass('fon').addClass('foff'); }
    else { $('#s1forward').removeClass('foff').addClass('fon'); }

    if (currSlide == 1) { $('#s1back').removeClass('bon').addClass('boff'); }
    else { $('#s1back').removeClass('boff').addClass('bon'); }

    IOM.updatedSlideHeight($(this));
}


IOM.updatedSlideNav2 = function(curr, next, opts) {

    var currSlide = opts.currSlide + 1;
    var totalSlides = opts.slideCount;

    if (currSlide == totalSlides) { $('#s2forward').removeClass('fon').addClass('foff'); }
    else { $('#s2forward').removeClass('foff').addClass('fon'); }
    if (currSlide == 1) { $('#s2back').removeClass('bon').addClass('boff'); }
    else { $('#s2back').removeClass('boff').addClass('bon'); }

    IOM.updatedSlideHeight($(this));
}


IOM.updatedAuthorsSlideNav = function(curr, next, opts) {/* perspective page author slideshow */

	var currSlide = opts.currSlide + 1;
	var totalSlides = opts.slideCount;
	
	var caption = '<li>' + currSlide + ' / ' + totalSlides + '</li>';
	$('#authorsnav').html(caption);

}

IOM.updateHint = function(event) {
    var hint = $(this).attr('title');
    if ($(this).val() == hint) {
        $(this).addClass('hint');
        if (event.type != undefined) { // not page refresh
            $(this).val('').removeClass('hint');
        }
    }
    else if ($(this).val() == '' || $(this).val() == hint) {
        $(this).val(hint).addClass('hint');
    }
}

//------
// INIT
//------

$(document).ready(function() {

	if ($.browser.msie) {
		$('html').addClass('msie' + $.browser.version.charAt(0));
	};

    // enable tabs, external links redirect 
    $('div.tabbed ul.tabs li').click(function() {
        if ($(this).parent().nextAll('div' + $('a', this).attr('href')).length > 0) {
            $(this).removeClass('off').addClass('on');
            $(this).siblings(':on').removeClass('on').addClass('off');
            $(this).parent().nextAll('div.tab').removeClass('on').addClass('off');
            $(this).parent().nextAll('div' + $('a', this).attr('href')).removeClass('off').addClass('on'); //
            // dispatch event
            $('a', this).blur();
            return false;
        }
    });

    // add first and last to li
    $('ul,ol').each(function() {
        $(this).children('li:first').addClass('first');
        $(this).children('li:last').addClass('last');
    });

    // add last to contact blocks
    $('div.module.contact > div.block2:last').addClass('last')

    // add last to content inside pop-up bubbles
    $('div.bubble div.content p:last').addClass('last');

    // feature slide show
    $('#featurecontent').cycle({
        fx: 'fade',
        speed: 'slow',
        timeout: 8000,
        pause: true,
        next: '#image-next',
        prev: '#image-previous',
        pager: '#featurenav',
        before: function() {

            do { var ranNum = Math.floor(Math.random() * IOM.slideshowColors.length); }
            while (ranNum == IOM.slideshowCurrColor);

            IOM.slideshowCurrColor = ranNum;
            $('div.header').css('background-color', '').css('background-color', IOM.slideshowColors[ranNum]);
        },
        pagerAnchorBuilder: function(idx, slide) {
            return '<li><a href="#">&nbsp;</a></li>';
        }

    });

    // regular slide show
    $('#s1').cycle({
        fx: 'scrollHorz',
        speed: 'slow',
        timeout: 0,
        nowrap: true,
        pause: true,
        next: '#s1forward',
        prev: '#s1back',
        pager: '#s1nav',
        after: IOM.updatedSlideNav1,
        pagerAnchorBuilder: function(idx, slide) {
            return '<li><a href="#">' + idx + '</a></li>';
        }
    });

    // regular slide show
    $('#s2').cycle({
        fx: 'scrollHorz',
        speed: 'slow',
        timeout: 0,
        nowrap: true,
        pause: true,
        next: '#s2forward',
        prev: '#s2back',
        pager: '#s2nav',
        after: IOM.updatedSlideNav2,
        pagerAnchorBuilder: function(idx, slide) {
            return '<li><a href="#">' + idx + '</a></li>';
        }
    });

/* perspect author slideshow */
if ($('body').hasClass('perspective') == true){
	$('div.info')
	.children('div.wrap')
	.siblings('p')			// add margin to top of asterisk'd p
		.css('clear', 'both');
	}
	
	// slide show
	$('#authors').cycle({
		fx: 'scrollHorz',
		speed: 'slow',
		timeout: 0,
		pause: true,
		next: '#authorsforward',
		prev: '#authorsback',
		pager: '#authorsnav',
		after: IOM.updatedAuthorsSlideNav,
		pagerAnchorBuilder: function(idx, slide) {
            return '<li style="display:none;">&nbsp;</li>';
		}
	});
		
	if($('#authors').children('.horz').length === 1){
		$('.horz')
		.children()
		.children('img')
		.css('padding-bottom', '11px')
		.parent()
		.parent()
		.parent('#authors')
		.css('height', '210px')
	}

    // accordions
    $("#accordion").accordion({
        header: "h3",
        autoHeight: false,
        clearStyle: true,
        alwaysOpen: false,
        active: false,
        cleartype: true
    });

    $("#accordion2").accordion({
        header: "h3",
        autoHeight: false,
        clearStyle: true,
        alwaysOpen: false,
        active: false,
        cleartype: true
    });

    $("#accordion3").accordion({
        header: "h3",
        autoHeight: false,
        clearStyle: true,
        alwaysOpen: false,
        active: false,
        cleartype: true
    });

    $("#accordionStudyStaff").accordion({
        header: "h3",
        autoHeight: false,
        clearStyle: true,
        alwaysOpen: false,
        active: false,
        cleartype: true
    });

    // enable titles to link externally
    $('ul.accordion > li a').hover(
	function() {
	    $(this).parents('ul.accordion:firt').accordion('disable')
	},
	function() {
	    $(this).parents('ul.accordion:firt').accordion('enable')
	});

    $('ul.accordion > li a.link').click(function() {
        window.location.href = $(this).attr('href');
    });

    $('ul.accordion > li.link h3').click(function() {
        var obj = $(this).find('a');
        var href = $(obj).attr('href');
        var target = $(obj).attr('target');

        if ($('a', this).length > 0) {
            if (target.length) {
                window.open(href, 'name');
            }
            else {
                window.location.href = href;
            }
        }
    });

    // open the accordion on selected node
    if ($('.accordion > li.on').length > 0) {
        var activeItemIndex = $('.accordion > li.on').prevAll('li').size();
        $("#accordion").accordion('activate', activeItemIndex);
    }

    // mark accordion tab as selected
    $('.accordion').bind('accordionchangestart', function(event, ui) {
        ui.oldHeader.parent().removeClass('on');
        ui.newHeader.parent().addClass('on');
    });


    // login button
    $("li.memberlogin,#memberloginbtn").click(function(e) {
        if ($("li.memberlogin").hasClass("on")) {
            IOM.closeLogin();
        }
        else {
            $("li.memberlogin").addClass("on");
            $("#memberlogin").fadeIn({ speed: 'fast' }).find("#username").focus();
        }
        e.stopPropagation()
        e.preventDefault();
    });

    // round corners of pop up bubbles
    DD_roundies.addRule('div.bubble div.content', '6px', true);

    // append pointer and reposition
    $('div.bubble').append('<div class="pointer">&nbsp;</div>');
    $('div.bubble.right div.pointer').css('margin-top', '-9px');

    $('a.bubble').click(function() {

        var bubbleContent = $('#' + $(this).attr('id') + '-txt');
        var documentOffset = $(this).offset();

        if (bubbleContent.hasClass('open')) {
            // close it
            IOM.closeBubble(bubbleContent);
        }
        else {
            // open it
            if ($.browser.msie) {
                $('div.bubble').removeClass('open').addClass('close');
                bubbleContent.removeClass('close').addClass('open');
            }
            else {
                $('div.bubble').fadeOut({ speed: 'fast' }).removeClass('open').addClass('close');
                bubbleContent.fadeIn({ speed: 'fast' }).removeClass('close').addClass('open');
            }

            // hide select fields for ie6, conflicts with pop-up bubble
            if ($.browser.msie && ($.browser.version < 7)) {
                $('select#keywordsearch').css('visibility', 'hidden');
            }
        }

        // reposition bubble next to '?' link
        if (bubbleContent.hasClass('right')) {
            var containerOffset = $(this).parents('ul.filter').offset();
            bubbleContent.css('top', (((documentOffset.top - containerOffset.top) - (bubbleContent.height() / 2)) + ($(this).height() / 2)) + 'px');
            bubbleContent.css('left', (documentOffset.left - containerOffset.left) + 'px');
        }

        $(this).blur();
        return false;
    });

    // close bubble when clicking anywhere on the screen
    $(document).click(function(e) {
        IOM.closeBubble($('div.bubble.open'));
    });

    IOM.closeBubble = function(_bubbleContent) {
        /* close popup bubble _bubbleContent:Object */

        if ($.browser.msie) {
            _bubbleContent.removeClass('open').addClass('close');
        }
        else {
            _bubbleContent.fadeOut({ speed: 'fast' }).removeClass('open').addClass('close');
        }

        // show select fields previously hidden for ie 6
        if ($.browser.msie && ($.browser.version < 7)) {
            $('select#keywordsearch').css('visibility', 'visible');
        }
    }

    //topics panel
    $("#explorebtn").click(function(e) {
        if ($(this).hasClass("on")) {
            IOM.closeTopicsPanel();
        }
        else {
            $(this).removeClass("off").addClass("on");
            $("#topics").slideDown({ speed: 'fast' });
        }

        e.stopPropagation()
        e.preventDefault();
    });


    // enable date picker
    if ($('#extraFilters').length == 0) {
        $('#datesearchfrom, #datesearchto').datepicker({
            changeMonth: true,
            changeYear: true,
            showOn: 'button',
            buttonImage: '/_res/img/icon_calendar.gif',
            buttonImageOnly: true
        });
    }

    // show filter options in chunks
    $('ul.options li.more').nextAll('li').hide();

    $('ul.options li.more').each(function() {
        $(this).data('index', $(this).prevAll('li').size());
        $(this).parent().append($(this));
    });

    $('ul.options li.more a').click(function(e) {
        $(this).parents('ul.options:first').find('li:hidden').slice(0, $(this).parent().data('index')).fadeIn();
        if ($(this).parents('ul.options:first').find('li:hidden').size() == 0) {
            $(this).parent().remove();
        }
        return false;
    });

    // add 'last' to last link anchor
    $('span.links a:last-child').addClass('last');

    // clear login on document click
    $(document).click(function(e) {
        var xxx = $(e.target);
        if (!xxx.is('input')) { IOM.closeLogin(); }

        //if panel is open close it..
        IOM.closeTopicsPanel();
    });

    // mark last item on column for images/logo pages
    $('ul.gallery li:nth(2)').addClass('last');

    // form hints
    $('textarea[title!=], :text[title!=]').each(IOM.updateHint);
    $('textarea[title!=], :text[title!=]').bind('focus', IOM.updateHint);
    $('textarea[title!=], :text[title!=]').bind('blur', IOM.updateHint);

    // find all slideshows, if no content turn pagers off
    $('.slideshow').each(function() {
        if ($(this).children('div').length == 1) {
            $('#' + this.id + 'forward').hide();
            $('#' + this.id + 'back').hide();
        }
    });

    // directory search, more options
    $('.moresearchopts a.searchoptsbtn').click(function(e) {

        var opts = $(this).siblings('div.searchopts')

        if (opts.is(':visible')) {
            opts.hide();
            $(this).removeClass('on').addClass('off');
            $(this).html('View More Search Options');
        }
        else {
            opts.show();
            $(this).removeClass('off').addClass('on');
            $(this).html('View Fewer Search Options');
        }

        e.preventDefault();
    });
	
    // activate lightbox for media pages
    if ($('ul.gallery').length > 0) {
        $('ul.gallery a.zoom').lightBox({
            overlayOpacity: 0.6,
            imageLoading: '/_res/img/lightbox/lightbox-ico-loading.gif',
            imageBtnClose: '/_res/img/lightbox/lightbox-btn-close.gif',
            imageBtnPrev: '/_res/img/lightbox/lightbox-btn-prev.gif',
            imageBtnNext: '/_res/img/lightbox/lightbox-btn-next.gif'
        });
    }

    $('ul.gallery a.zoom').append('<span class="magnify"><\/span>');
    $('ul.gallery a.zoom span').hide();
    $('ul.gallery a').hover(
		function() {
		    $('span', this).fadeIn('fast');
		},
		function() {
		    $('span', this).fadeOut('fast');
		}
	);

    // activate lightbox for other pages
	/* legacy code; retained to keep functionality for older pages that do not have the div.lightbox */
	// if there is more than one link per page, make a gallery
    if ($('a.zoom').length > 0) {
        $('a.zoom').lightBox({
            overlayOpacity: 0.6,
            imageLoading: '/_res/img/lightbox/lightbox-ico-loading.gif',
            imageBtnClose: '/_res/img/lightbox/lightbox-btn-close.gif',
            imageBtnPrev: '/_res/img/lightbox/lightbox-btn-prev.gif',
            imageBtnNext: '/_res/img/lightbox/lightbox-btn-next.gif'
        });
    }
	
	/* begin revised code incorporating magnifying glass */
	var magnifySpan = $('<span class="magnify"><\/span>');
	
	// if there is more than one link per page, make a gallery
	if ($('div.lightbox a.zoom').length > 0) {
		$('div.lightbox a.zoom').lightBox({
			overlayOpacity: 0.6,
			imageLoading: '/_res/img/lightbox/lightbox-ico-loading.gif',
			imageBtnClose: '/_res/img/lightbox/lightbox-btn-close.gif',
			imageBtnPrev: '/_res/img/lightbox/lightbox-btn-prev.gif',
			imageBtnNext: '/_res/img/lightbox/lightbox-btn-next.gif'
		});
	}

	//single images use div.lighbox
	$('div.lightbox a.zoom').append(magnifySpan);
    $('div.lightbox a.zoom span').hide();
    $('div.lightbox a').hover(
		function() {
			//get image height, width, and how far to the left of the parent element to center the mag glass in the image
			//because the images are not contained in a lightbox, so have different heights, width, positions, kinds of containing elements
			var imgWidth	= $(this).children('img').width();
			var imgHeight	= $(this).children('img').height();
			var imgLeft		= $(this).children('img').position().left;
		
		    $('span', this).fadeIn('fast')
				.css('width', imgWidth)
				.css('height', imgHeight)
				.css('left', imgLeft);
		},
		function() {
		    $('span', this).fadeOut('fast');
		}
	);
	
	//infographics use div.lightbox a.thickbox
    $('div.lightbox a.thickbox').append(magnifySpan);
    $('div.lightbox a.thickbox span').hide();
    $('div.lightbox a.thickbox').hover(
		function() {
			//get image height, width, and how far to the left of the parent element to center the mag glass in the image
			var imgWidth	= $(this).children('img').width();
			var imgHeight	= $(this).children('img').height();
			var imgLeft		= $(this).children('img').position().left;
		
		    $('span', this).fadeIn('fast')
				.css('width', imgWidth)
				.css('height', imgHeight)
				.css('left', imgLeft);
		},
		function() {
		    $('span', this).fadeOut('fast');
		}
	);

    // activate collapsible lists
    $('ul.collapsible > li h3').click(function() {
        if ($(this).parent().hasClass('on')) {
            $(this).parent().removeClass('on').addClass('off');
        }
        else {
            $(this).parent().removeClass('off').addClass('on');
        }
    });

    // enable increase text size widget
    $('a.textincrease').click(function(e) {
        IOM.toggleTextSize(true);
        e.preventDefault();
    });

    // enable decrease text size
    $('a.textdecrease').click(function(e) {
        IOM.toggleTextSize(false);
        e.preventDefault(false);
    });

    // load saved text size
    IOM.loadSavedTextSize();



});

// video page additions
jQuery(function($) {
    $('div.page li,div.page div.block')
                .click(function(e) {
                    $('li.playing, div.playing').removeClass('playing');

                    if ($(this).parents('ul').size() === 1) {
                        $(this).addClass('playing');
                    }
                    else {
                        $(this).find('div.pad').addClass('playing');
                    }

                    var url = $(this).find('a').attr('href');
                    $('div.videoWrapper')
                        .append('<div class="videoLoading"></div>')
                        .load(url + ' div.moduleVideo', function() { });

                    window.scrollTo(0, 0);
                    e.preventDefault();
                });
});

jQuery(function($) {
    $('div.tabBody').each(function(i) {

        var num = $(this).find('div.page').size();
        var obj = $(this);

        if (num > 1) {
            $(this)
                        .append('<div class="link vidPageBar"><ul class="pagination"></ul></div>')
                        .find('ul.pagination')
                        .append('<li><a href="#" class="back off">prev</a></li>')
                        .end()
                        .find('div.page')
                        .each(function(j) {
                            $(this)
                                .parent()
                                .find('ul.pagination')
                                .append('<li' + ((j == 0) ? ' class="activeItem"' : '') + '><a href="#">' + eval(j + 1) + '</a></li>');
                        })
                        .end()
                        .find('ul.pagination')
                        .append('<li><a href="#" class="forward on">next</a></li>')
                        .find('li:first-child a')
                        .click(function(e) {

                            var obj = $(this).parents('ul.pagination').find('li.activeItem').eq(0);
                            var index = $(this).parents('ul.pagination').find('li').index(obj);

                            if (index > 1) {
                                $(this)
                                    .parents('div.tabBody')
                                    .find('ul.pagination')
                                    .each(function() {
                                        $(this)
                                            .find('li.activeItem')
                                            .removeClass('activeItem')
                                            .prev()
                                            .addClass('activeItem');
                                    })
                                    .end()
                                    .find('div.activeItem')
                                    .removeClass('activeItem')
                                    .prev()
                                    .addClass('activeItem');
                            }

                            e.preventDefault();
                        })
                        .end()
                        .find('li:last-child a')
                        .click(function(e) {

                            var obj = $(this).parents('ul.pagination').find('li.activeItem').eq(0);
                            var index = $(this).parents('ul.pagination').find('li').index(obj);
                            var size = $(this).parents('ul.pagination').find('li').size() - 2;

                            if (index < size) {

                                $(this)
                                    .parents('div.tabBody')
                                    .find('ul.pagination')
                                    .each(function() {
                                        $(this)
                                            .find('li.activeItem')
                                            .removeClass('activeItem')
                                            .next()
                                            .addClass('activeItem');
                                    })
                                    .end()
                                    .find('div.activeItem')
                                    .removeClass('activeItem')
                                    .next()
                                    .addClass('activeItem');
                            }

                            e.preventDefault();
                        })
                        .end()
                        .end()
                        .find('ul.pagination a')
                        .not('li:first-child a, li:last-child a')
                        .click(function(e) {
                            var num = $(this).html();

                            $(this)
                                .parents('div.tabBody')
                                .find('ul.pagination li.activeItem')
                                .removeClass('activeItem')
                                .end()
                                .end()
                                .parent()
                                .addClass('activeItem')
                                .parents('div.tabBody')
                                .find('div.activeItem')
                                .removeClass('activeItem')
                                .end()
                                .children('div')
                                .eq(num)
                                .addClass('activeItem')
                                .end()
                                .end()
                                .end()
                                .each(function() {
                                    var index = $(this).parents('ul.pagination').find('li').index($(this));
                                    $(this)
                                        .parents('div.tabBody')
                                        .find('ul.pagination')
                                        .each(function() {
                                            $(this)
                                                .find('li')
                                                .eq(index)
                                                .addClass('activeItem');
                                        });
                                });

                            e.preventDefault();
                        })
                        .end()
                        .end()
                        .find('div.vidPageBar')
                        .clone(true)
                        .prependTo(obj);
        }
    });

    $('div.videoSessionsList a').click(function(e) {
        var id = $(this).attr('href').split('#')[1];

        $(this)
                    .parents('ul')
                    .find('li.activeItem')
                    .removeClass('activeItem')
                    .end()
                    .end()
                    .parents('li')
                    .eq(0)
                    .addClass('activeItem');

        $('div.tabsBody div.activeItem').removeClass('activeItem');

        $('#' + id)
                    .addClass('activeItem')
                    .find('div.page')
                    .eq(0)
                    .addClass('activeItem')
                    .end()
                    .end()
                    .find('ul.pagination')
                    .each(function() {
                        $(this)
                            .find('li.activeItem')
                            .removeClass('activeItem')
                            .end()
                            .find('li:first-child')
                            .next()
                            .addClass('activeItem');
                    });

        e.preventDefault();
    });

    $('#accordion4')
                .find('h3')
                .not('.on')
                .next()
                .hide()
                .end()
                .end()
                .click(function() {
                    if ($(this).is('.on')) {
                        /* shouldn't be able to close one;
                        $(this)
                        .parent()
                        .removeClass('on')
                        .end()
                        .removeClass('on')
                        .next()
                        .slideUp();
                        */
                    }
                    else {
                        $(this)
                            .parent()
                            .siblings('.on')
                            .removeClass('on')
                            .find('h3.on')
                            .removeClass('on')
                            .next()
                            .slideUp()
                            .end()
                            .end()
                            .end()
                            .addClass('on')
                            .end()
                            .addClass('on')
                            .next()
                            .slideDown()
                            .end()
                            .find('a')
                            .click();
                    }
                });
});
