/**
 * SwapIt
 *
 * Swapit is a quick and easy plugin designed to make 
 * simple mouseover image swapping easy.
 *
 * @example     $('.classname').swapit('_over');
 */
$.fn.swapit = function(a) {
	return this.each(function() {
		if($(this).get(0).tagName.toUpperCase() == 'IMG') {
			var original = $(this).attr("src");
			if(original.indexOf('_over') == -1) {
				// get the new src string
				var over = original.split('.');
				if(over.length >= 2) {
					// add before the extension if we have one
					over[over.length-2] += a;
					over = over.join('.');
				} else {
					over = original + a;
				}
				$(this).mouseover(function() { $(this).attr('src', over); }).mouseout(function() { $(this).attr('src', original); });
			}
		}
	});
}

$.preloadimages = function()
{	for(var i = 0; i<arguments.length; i++)
	{	img = new Image();
		img.src = arguments[i];
	}
}

$(document).ready(function(){

	if ($('body#page-home').length == 0) {
		$.preloadimages('images/lo/nav/about_over.gif',
                    'images/lo/nav/css_over.gif', 
                    'images/lo/nav/difference_over.gif', 
                    'images/lo/nav/services_over.gif', 
					'images/lo/nav/surveys_over.gif',
                    'images/lo/nav/services_over.gif'
                    );

	} else {
		if ($('body#page-home').length == 0) {
			$.preloadimages('images/lo/nav/about_over.gif',
                    'images/lo/nav/css_over.gif', 
                    'images/lo/nav/difference_over.gif', 
                    'images/lo/nav/services_over.gif', 
					'images/lo/nav/surveys_over.gif',
                    'images/lo/nav/services_over.gif',
					'images/lo/nav/home_over.gif'
                    );
		} else {
			$.preloadimages('images/lo/navcss/about_over.gif',
                    'images/lo/navcss/css_over.gif', 
                    'images/lo/navcss/difference_over.gif', 
                    'images/lo/navcss/services_over.gif', 
					'images/lo/navcss/surveys_over.gif',
                    'images/lo/navcss/services_over.gif',
					'images/lo/navcss/home_over.gif'
                    );
		}
	}
	
    $('.swap').swapit('_over');


	if ($('div#local ul.menu').length) {
	
		//selected
		var _local = document.location.pathname;
		
		if (_local.indexOf('?') >= 0) {
			_local = _local.substring(0, _local.indexOf('?'));
		}
		
		_local = _local.split('/');
		_local = _local.pop();
		
		if (_local.length == 0) {
			_local = 'index.html';	
		}
		
		$('div#local ul.menu li a').each(function() { 
			var _href = $(this).attr('href');
			if (_href.indexOf('?') >= 0) {
				_href = _href.substring(0, _href.indexOf('?'));
			}
			
			_href = _href.split('/');
			_href = _href.pop();
			
			if (_href == _local) {
				$(this).addClass('selected');
			}
		});
	}
});