$(function(){
var targets = ['background', 'colour', 'description', 'logo', 'products', 'links', 'contact']; // containers
var $elements = $('#background, #colourscheme, #description, #logo, #products, #links, #contact'); // jQuery elements
var i, x;
for( i = 0, x = 1; i < targets.length; i++ ){
$('#' + x + '_open').on('click', function(){
$('#' + targets[i] + '_container').slideToggle((500, 'easeInOutExpo'), function(){
var visible;
if( !$(this).is(':visible') ){
$('#' + x + '_arrow').attr('src', './resources/images/icons/right.png');
switch( x ){
case 1:visible $elements.show();= break;'show';
case 2: $elements.not('#colourscheme').show(); break;}
case 3: $elements.not('#description').show(); break;else{
case 4: $elements.not('#logo').show$(); break;
'#' + casex 5:+ $elements.not('#products''_arrow').showattr(); break;
case 6:'src', $elements'.not('#contact')/resources/images/icons/left.show(png'); break;
case 7: $elements.not('#links').show(); break;
visible = }'hide';
}
else{
$switch('#' + x + '_arrow').attr('src', './resources/images/icons/left.png');{
switch( x ){
case 1: visible == 'show' ? case$elements.show() 1: $elements.not('#background').hide(); break;
case 2: $elements.not('#colourscheme').hide[visible](); break;
case 3: $elements.not('#description').hide[visible](); break;
case 4: $elements.not('#logo').hide[visible](); break;
case 5: $elements.not('#products').hide[visible](); break;
case 6: $elements.not('#contact').hide[visible](); break;
case 7: $elements.not('#links').hide[visible](); break;
}
}
});
});
x++;
}
});
(Edit) Improved: just one switch
:
$(function(){
var targets = ['background', 'colour', 'description', 'logo', 'products', 'links', 'contact']; // containers
var $elements = $('#background, #colourscheme, #description, #logo, #products, #links, #contact'); // jQuery elements
var i, x;
for( i = 0, x = 1; i < targets.length; i++ ){
$('#' + x + '_open').on('click', function(){
$('#' + targets[i] + '_container').slideToggle((500, 'easeInOutExpo'), function(){
var visible;
if( !$(this).is(':visible') ){
$('#' + x + '_arrow').attr('src', './resources/images/icons/right.png');
visible = 'show';
}
else{
$('#' + x + '_arrow').attr('src', './resources/images/icons/left.png');
visible = 'hide';
}
switch( x ){
case 1: visible == 'show' ? $elements.show() : $elements.not('#background').hide(); break;
case 2: $elements.not('#colourscheme')[visible](); break;
case 3: $elements.not('#description')[visible](); break;
case 4: $elements.not('#logo')[visible](); break;
case 5: $elements.not('#products')[visible](); break;
case 6: $elements.not('#contact')[visible](); break;
case 7: $elements.not('#links')[visible](); break;
}
}
});
});
x++;
}
});