﻿     $(function(){
        var pause = 3500;
        var speed = (17.5/100)*pause;
        var ie7 = 0;
	    var fadeOutSpeed = (25/100)*pause;
	    
	    // Setting the Mover left Pos
	    
	    var totalWidth=$('#NewsContainer').width();
	    
	    $('#move_Previous,#move_Next').css({'left':totalWidth/2-26});
	    
         // Setting the News Ul Height
         var licount=$('#listticker li').length;
         if(licount>=3)
         {
            var liMargin=parseFloat($('#listticker li:first').css('marginBottom'),10)+parseFloat($('#listticker li:first').css('marginTop'),10);
            var liPadding=parseFloat($('#listticker li:first').css('paddingBottom'),10)+parseFloat($('#listticker li:first').css('paddingTop'),10);
            var containerHeight = ($('#listticker li:first').height()+liMargin+liPadding)*(licount-1);
            if(containerHeight>280)containerHeight=280;
            $('#listticker').animate({'height':containerHeight},1500);
            //$('#move_Previous').css({'top':containerHeight-10});
         }
         else
         {
            $('#move_Next').remove();
            $('#listticker').animate({'height':($('#listticker li:first').height()*(licount))+((licount)*10)},1500);
            clearInterval(interval);
         }
         function newsticker_Next()
         {
              // algorithm:
              // First setting the height, padding and margin of the first li to 0.
              // this make all other li move to above.
              // second remove the first li
              // third add it at the end position.
              first = $('ul#listticker li:first');
              $('#listticker li').first().animate({opacity: 0, paddingTop: 0, paddingBottom: 0, height: 0, marginTop: -ie7, top: ie7},{duration:fadeOutSpeed,easing:'easeInOutExpo', complete:function(){
              $('ul#listticker li:first').remove();
              $('ul#listticker').append(first.removeAttr('style'));
              },queue:true});
         }
         interval = setInterval(newsticker_Next, pause);
         $('#listticker').hover(function(){
            $('.forceMove').animate({'opacity':.8},'fast');
            clearInterval(interval);
            },
            function(){
                interval = setInterval(newsticker_Next, pause);
                $('.forceMove').animate({'opacity':0},'fast');
         });
         
         $('.forceMove').hover(function(){
            clearInterval(interval);
            $('#listticker').animate({'opacity':.5},'fast');
            $(this).animate({'opacity':1},'fast');
            },
            function(){
                interval = setInterval(newsticker_Next, pause);
                $('#listticker').animate({'opacity':1},'fast');
                
            });
         $('#move_Next').click(newsticker_Next);
         $('#move_Previous').click(newsticker_Prev);
    }); 
     function newsticker_Prev()
     {
          // algorithm:
          // get last element, remove it from the list,
          // add to first position with hidden style
          // slideDown the new first element
          // continue
          last = $('ul#listticker li:last').hide().remove();
          $('ul#listticker').prepend(last);
          $('ul#listticker li:first').css({'height':'0px','opacity':0}).animate({'height':'60px','opacity':1},'slow','easeInOutExpo');
     }

