$(document).ready(function(){ //Base movement speed for all functions on this page var nMovementSpeed = 300; var nScrollPercent = '20.3%'; var nMaxScrollOffset = 5; $('.televisionContent').click(function(){ if($(this).attr('data-url')){ location.href=$(this).data('url'); } }); if($(window).width()<=700){ nScrollPercent = '24.8%'; nMaxScrollOffset = 4; } if($(window).width()<=450){ nScrollPercent = '50%'; nMaxScrollOffset = 2; } //When the window is resized find out the width and set the scrolling content variables accordingly $( window ).resize(function() { if($(window).width()>700){ nScrollPercent = '20.3%'; nMaxScrollOffset = 5; } if($(window).width()<=700){ nScrollPercent = '24.8%'; nMaxScrollOffset = 4; $(document).find('.televisionContentWrapper').each(function(index){ $(this).animate({left: "0px"}, nMovementSpeed); $(this).parent().parent().data('currentscroll', '0'); }); } if($(window).width()<=450){ nScrollPercent = '50%'; nMaxScrollOffset = 2; $(document).find('.televisionContentWrapper').each(function(index){ $(this).animate({left: "0px"}, nMovementSpeed); $(this).parent().parent().data('currentscroll', '0'); }); } }); $('.televisionNav').each(function(index){ var nAreaItemCount = $(this).parent().data('maxscroll'); if(nAreaItemCount <= nMaxScrollOffset){ $(this).hide(); } }); //When a more televisions button is clicked $('.televisionRight').click(function(){ //Get the current scroll amount var nThisCurrentScroll = parseInt($(this).parent().data('currentscroll')); var nMaxScroll = $(this).parent().data('maxscroll'); //if current scroll count is more than five items away from the end then allow the user to scroll forward by 1 and increment the value accordingly if(nThisCurrentScroll= nRightSideLimit){ $(this).find('img.televisionRight').stop().animate({opacity: 1}, nMovementSpeed); }else{ $(this).find('img.televisionRight').stop().animate({opacity: 0.4}, nMovementSpeed); } }); });