/*Carousel MS - corporate */ function initCarousel(width, visibleItems){ list = $('.h_carousel ul'); 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').click(function(){ list=$(this).parent().parent().children('ul'); if(canMove('right', $(this))){ moveCarousel('right', $(this)); } return false; }); $('.previous').click(function(){ list=$(this).parent().parent().children('ul'); if(canMove('left', $(this))){ moveCarousel('left', $(this)); } return false; }); } function moveCarousel(direction, element){ var value = item_width; if(direction=='right'){ value *= -1 } $('.next').unbind('click'); $('.previous').unbind('click'); list.animate({left: (getCurrentPosition() + value) + 'px'}, {duration:200, queue:true, complete: function(){ attachEvents(); checkArrowsStatus(); } }); } function checkArrowsStatus(){ if(!canMove('left')){ list.next().children('.previous').addClass('previous_button_disabled'); list.next().children('.previous').fadeTo(200, 0.3); }else{ list.next().children('.previous').removeClass('previous_button_disabled'); list.next().children('.previous').fadeTo(200, 1); } if(!canMove('right')){ list.next().children('.next').addClass('next_button_disabled'); list.next().children('.next').fadeTo(200, 0.3); }else{ list.next().children('.next').removeClass('next_button_disabled'); list.next().children('.next').fadeTo(200, 1); } } function canMove(direction, element){ 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; }