$(document).ready(function(){
var slider = $('#slider');
if ( slider.length > 0 ) {
function sliderProgress() {
clearTimeout(sliderTimer);
posi = $('#slider-position li').index(this) + 1;
slider.find('img.selected').fadeOut(function(){
$(this).removeClass('selected');
});
$('#slider-img-' + posi).fadeIn(function(){
$(this).addClass('selected');
});
sliderposition.find('.selected').removeClass('selected').click(sliderProgress);
$(this).addClass('selected').unbind('click');
sliderTimer = setupTimeout();
}
function setupTimeout() {
return setTimeout( function(){
nextPosi = sliderposition.find('.selected').next();
if ( nextPosi.length === 0 ) {
nextPosi = sliderposition.children().first();
}
nextPosi.trigger('click');
}, 8000 );
}
sliderImages = slider.find('img');
sliderposition = $('
');
for(var i=0;i
');
// Adding a link to the swControls div:
swControls.append('
'+(i+1)+'');
}
ul.append(swControls);
var maxHeight = 0;
var totalWidth = 0;
var swPage = ul.find('.swPage');
swPage.each(function(){
// Looping through all the newly created pages:
var elem = $(this);
var tmpHeight = 0;
elem.find('li').each(function(){tmpHeight+=$(this).data('height');});
if(tmpHeight>maxHeight)
maxHeight = tmpHeight;
totalWidth+=elem.outerWidth();
elem.css('float','left').width(ul.width());
});
swPage.wrapAll('
');
// Setting the height of the ul to the height of the tallest page:
//ul.height(maxHeight);
var swSlider = ul.find('.swSlider');
swSlider.append('
').width(totalWidth);
var hyperLinks = ul.find('a.swShowPage');
hyperLinks.click(function(e){
// If one of the control links is clicked, slide the swSlider div
// (which contains all the pages) and mark it as active:
$(this).addClass('active').siblings().removeClass('active');
$(".swPage#page_"+$(this).html()).addClass('active').siblings().removeClass('active');
ul.height($(".swPage.active").height());
swSlider.stop().animate({'margin-left':-(parseInt($(this).text())-1)*ul.width()},0);
$( 'html, body' ).animate( { scrollTop: 0 }, 0 );
e.preventDefault();
});
// Mark the first link as active the first time this code runs:
hyperLinks.eq(0).addClass('active');
$(".swPage#page_1").addClass('active');
// Center the control div:
swControls.css({
'left':'50%'
//'margin-left':-swControls.width()/2
});
ul.height($(".swPage#page_1").height());
return this;
}})(jQuery);