$(document).ready(function(){ 
  $(document).pngFix();
		
  var liCount =0;
	var colCount=0;
	var extraClass = '';
	var liAverage = $('#siteMap li').length / 5;
	var newSiteMap = '<div class="col col0"><ul>';
		
	// small script to divide the sitemapfooter evenly across 5 cols		
	$('#siteMap li').each(function(index){
		if($(this).attr('class') != $(this).next().attr('class')) {
			extraClass = 'last';
    }
		else {
			extraClass = '';
		}
		newSiteMap = newSiteMap + '<li class="'+$(this).attr('class')+'"><a class="'+extraClass+'" href="'+$(this).children('a').attr('href')+'">'+$(this).children('a').html()+'</a></li>';
			
		if(liCount > liAverage) {
			colCount = colCount + 1;
			newSiteMap = newSiteMap + '</ul></div><div class="col col'+colCount+'"><ul>';
			liCount = 0;
		}
		liCount = liCount + 1;
	});
	newSiteMap = newSiteMap + '</ul></div>';
	$('#siteMap').html(newSiteMap);
	// end sitemap script
	
	$('#search .form-text').val('Search'); 
	// Auto clear search box text
	$('#search .form-text').focus(function() {
		if($(this).val() == 'Search'){
			$(this).val('');
		}
	});
	
  $('#search .form-text').blur(function() {
		if($(this).val() == ''){
			$(this).val('Search');
		}
	});
		
	// Preload navigation images
	menuHoverImage = new Image(); 
	menuHoverImage.src = '<?php print base_path() . path_to_theme(); ?>/skin/img/down-over.gif';
	menuHoverRightImage = new Image(); 
	menuHoverRightImage.src = '<?php print base_path() . path_to_theme(); ?>/skin/img/right-over.gif';
        
	// add scrolling to back to top link                       
	$.localScroll();

  // initialize scrollable  
  $("div.scrollable").scrollable({
    size: 1,
    prev: '.previous',
    next: '.next',
    loop: true,
    items: '.items',
    speed: 300,
    interval: 5000
  });
});
