(function($){
  $.fn.shuffle = function() {
    return this.each(function(){
      var items = $(this).children();
      return (items.length)
        ? $(this).html($.shuffle(items))
        : this;
    });
  }
 
  $.shuffle = function(arr) {
    for(
      var j, x, i = arr.length; i;
      j = parseInt(Math.random() * i),
      x = arr[--i], arr[i] = arr[j], arr[j] = x
    );
    return arr;
  }
})(jQuery);
$(document).ready(function(){ 
	        $('ul.sf-menu').superfish({ 
            pathClass:  'current',
            delay:       1000,                         // one second delay on mouseout 
			speed:		 500,
            autoArrows:  false,                           // disable generation of arrow mark-up 
            dropShadows: false                            // disable drop shadows 
        }); 
		
		
		$("#clientsCarousel ul").shuffle();
		$("#clientsCarousel").jCarouselLite({speed: 1500,auto: 3000, visible: 6, mouseWheel: true});
		
		$('#clientTextShow').click(function(){
			curText = $(this).text();
			newText = curText == 'Свернуть' ? 'Развернуть' : 'Свернуть';
			$(this).text(newText).prev('div').slideToggle('slow');
			return false;
		});
	
		$('#dept-menu ul').each(function () {
												   $(this).children(':last').addClass('last')
												   }
												  );
		
		$('#nav-menu ul').each(function () {
												   $(this).children(':last').addClass('last')
												   }
												  );

		$('table.sortable').tablesorter({sortList: [[0,0]], widgets: ['zebra']});
		
		$('ul.toright').each(
			function (i) { 
			var childs = $(this).children().length;
			var width = 115;
			$(this).css('width',width*childs+childs+1)
				
				}
		);
		
		var searchStr = $('#topSearchInput').val();
		
		$('#topSearchInput').focus(function() {
					if ($(this).val() == searchStr) {
						$(this).val('');}
								  }
		);
		
		$('#topSearchInput').blur(function() {
				if ($(this).val() == '') {
					$(this).val(searchStr);}
				  }
		);

		$("a[rel$='external']").live('click',function(){
				 $(this).attr('target','_blank');
		});
		


    }); 
