I'm trying to use this content switcher. And I've got it working fine in JS Fiddle. But when I try to implement it on my site it doesn't work properly. The first panel displays correctly and when I click the link it fades to the second panel correctly.
BUT, when I click the first or any other link it fades the same content (from whatever link is first clicked) in again. Here's the page with the broken slider. Any help would be much appreciated.
The HTML:
<div id="fp_nav" class="text_box">
<a id="ourstory" class="switcher">Our Story</a>
<a id="ourpeople" class="switcher">Our People</a>
<a id="ourcustomers" class="switcher">Our Customers</a>
<a id="contactus" class="switcher">Contact Us</a>
</div>
<div id="switcher-panel" class="content">
<div id="ourstory-content" class="switcher-content show"><strong>BREAD OF LIFE BAKERY</strong> is a non-profit organization run by physically disabled young adults...</div>
<div id="ourpeople-content" class="switcher-content"><strong>Our People</strong> are good people.</div>
<div id="ourcustomers-content" class="switcher-content"><strong>Our Customers</strong> are really good customers.</div>
<div id="contactus-content" class="switcher-content"><strong>Contact Us</strong> to order some really great bakery items.</div>
</div>
And the jQuery:
var jcps = {};
jcps.fader = function (speed, target, panel) {
jcps.show(target, panel);
if (panel == null) {
panel = ''
};
jQuery('.switcher' + panel).click(function () {
var _contentId = '#' + jQuery(this).attr('id') + '-content';
var _content = jQuery(_contentId).html();
if (speed == 0) {
jQuery(target).html(_content);
} else {
jQuery(target).fadeToggle(speed, function () {
jQuery(this).html(_content);
}).fadeToggle(speed);
}
});
};
jcps.slider = function (speed, target, panel) {
jcps.show(target, panel);
if (panel == null) {
panel = ''
};
jQuery('.switcher' + panel).click(function () {
var _contentId = '#' + jQuery(this).attr('id') + '-content';
var _content = jQuery(_contentId).html();
if (speed == 0) {
jQuery(target).html(_content);
} else {
jQuery(target).slideToggle(speed, function () {
jQuery(this).html(_content);
}).slideToggle(speed);
}
});
};
jcps.show = function (target, panel) {
jQuery('.show').each(function () {
if (panel == null) {
jQuery(target).append(jQuery(this).html() + '<br/>');
} else {
var trimPanel = panel.replace('.', '');
if (jQuery(this).hasClass(trimPanel) == true) {
jQuery(target).append(jQuery(this).html() + '<br/>');
}
}
});
}
jQuery(document).ready(function () {
jcps.fader(300, '#switcher-panel');
});
And a very small amount of CSS:
.switcher-content {
display: none;
}