/*Carousel MS - corporate */ function initCarousel(width, visibleItems){ list = $('ul#thumbs'); if(list.size() > 0) { item_width = width; visible_items = visibleItems; attachEvents(); checkArrowsStatus(); $('.thumbImage').each(function(){ var img = $(this).attr('href'); $(this).attr('href','#'); $(this).attr('target', ''); $(this).click(function(){ $('.img_dett img').attr('src', img); $('a.selected').removeClass('selected'); $(this).addClass('selected'); return false; }) if($('a.selected').size() == 0) $('.thumbImage').eq(0).addClass('selected'); }); } } function attachEvents(){ $('.next_button').click(function(){ if(canMove('right')){ moveCarousel('right'); } }); $('.previous_button').click(function(){ if(canMove('left')){ moveCarousel('left'); } }); } function moveCarousel(direction){ var value = item_width; if(direction=='right'){ value *= -1 } $('.next_button').unbind('click'); $('.previous_button').unbind('click'); list.animate({left: (getCurrentPosition() + value) + 'px'}, {duration:200, queue:true, complete: function(){ attachEvents(); checkArrowsStatus(); } }); } function checkArrowsStatus(){ if(!canMove('left')){ $('.previous_button').addClass('previous_button_disabled'); $('.previous_button').fadeTo(200, 0.3); }else{ $('.previous_button').removeClass('previous_button_disabled'); $('.previous_button').fadeTo(200, 1); } if(!canMove('right')){ $('.next_button').addClass('next_button_disabled'); $('.next_button').fadeTo(200, 0.3); }else{ $('.next_button').removeClass('next_button_disabled'); $('.next_button').fadeTo(200, 1); } } function canMove(direction){ var currentPosition = getCurrentPosition(); //return ((direction=='left' && getCurrentPosition() > 0)||(direction=='left' && ( getCurrentPosition() < totalWidht ) )); return((direction=='right' && getCurrentPosition() + (getListWidth() - (item_width* visible_items)) > 0)||(direction=='left' && getCurrentPosition() < 0)) } function getCurrentPosition(){ return list.position().left; } function getListWidth(){ return list.children().length * item_width; }