$(document).ready(function(){
	$('#navbar .active').append('<img class="nav-activebox" src="common/css/BM/sgraphics/activebox.png" alt="pointer"/>');
    var count=0;
    $('.scrollable-horizontal').each(function(){
        count=count+1;
        $(this).attr('id','scroll-'+count);
        $(this).after('<img id="scroll-'+count+'-arrow" class="scroll-left scroll" src="/common/css/PTC/sgraphics/left.png">');
        $(this).after('<img id="scroll-'+count+'-arrow" class="scroll-right scroll" src="/common/css/PTC/sgraphics/right.png">');
    });
    $('.scrollable-vertical').each(function(){
        count=count+1;
        $(this).attr('id','scroll-'+count);
        $(this).before('<img id="scroll-'+count+'-arrow" class="scroll-up scroll" src="/common/css/PTC/sgraphics/up.png">');
        $(this).after('<img id="scroll-'+count+'-arrow" class="scroll-down scroll" src="/common/css/PTC/sgraphics/down.png">');
    });
    $('.scroll').mouseenter(function(){
        var i = $(this).attr('id');
        var x = i.lastIndexOf('-arrow');
        i = i.substring(0,x);
        var d = $(this).attr('class');
        x = d.lastIndexOf('scroll-')+7;
        d = d.substring(x,d.indexOf(' ',x));
        scroller = setInterval('scroll("'+d+'","'+i+'")',15);
    });
    $('.scroll').mouseleave(function(){
        clearInterval(scroller);
    });
    window.setTimeout("$('.vertical-bar').each(function(){var x = $(this).parent().css('height');$(this).height(x);});",200);
	
	//modified to limit to five per category
	$.widget( "custom.catcomplete", $.ui.autocomplete, {
			_renderMenu: function( ul, items ) {
				var self = this,
					currentCategory = "";
				var i = 0; //counter for categories
				$.each( items, function( index, item ) {
					if ( item.category != currentCategory ) {
						ul.append( "<li class='ui-autocomplete-category'>" + item.category + "</li>" );
						currentCategory = item.category;
						i = 0; //reset counter for next category
					}
					if(i++<5) //check and increment counter
						self._renderItem( ul, item );
				});
			}
	});
	$( "#searchText" ).catcomplete({
				source: "search.php",
				minLength: 2,
				select: function( event, ui ) {
					window.location.href=ui.item.path;
				}

	});
});
function scroll(direc, elem){
    if(direc=="left")
        $('#'+elem).scrollLeft($('#'+elem).scrollLeft()-2);
    else if(direc=="right")
        $('#'+elem).scrollLeft($('#'+elem).scrollLeft()+2);
    else if(direc=="up")
        $('#'+elem).scrollTop($('#'+elem).scrollTop()-2);
    else if(direc=="down")
        $('#'+elem).scrollTop($('#'+elem).scrollTop()+2);
}
function tabs(parent, elem){
    $(parent+' ul.tabs li').removeClass('active');
    $(parent+' > div').removeClass('active');
    $(parent+' '+elem).addClass('active');
}
