/* ------------------------------------------------------------------------
 * Plugin: downstate
 * Author: Ryan Molley
 * Company: Red Hawk Technologies (http://www.redhawk-tech.com)
 * Version: 1.0
 * Completion: August 15, 2011
 * ------------------------------------------------------------------------- */
(function(jQuery) {
		  
	jQuery(function() {
		var path = window.location.pathname;
		var object = jQuery('li[dstart]').get();
		
		jQuery.each(object, function(index, item) {
			var dclass, dstart, dexact, dimage;
			
			dstart = jQuery(item).attr('dstart');
			dexact = jQuery(item).attr('dexact');
			dimage = jQuery(item).attr('dimage');
			dclass = jQuery(item).attr('dclass');
			
			dexact ? getd(dexact.split(',')) : getd(dstart.split(','));
			
			function getd(multi) {
				jQuery.each(multi, function(i, value) {
							
					if(dexact) {
						if(path.toLowerCase() == value.toLowerCase()) {
							dostuffd();
							return false;
						}
					}
					else if(dstart) {
						if(path.toLowerCase().indexOf(value.toLowerCase()) > -1) {
							dostuffd();
							return false;
						}
					}
					
					function dostuffd() {
						if(dimage) {
							jQuery(item).find('img').attr('src', dimage);
								
							if(jQuery(item).find('img').attr('onmouseover')) {
								jQuery(item).find('img').attr('onmouseover', 'this.src=\'' + dimage + '\';');
								jQuery(item).find('img').attr('onmouseout', 'this.src=\'' + dimage + '\';');
							}
						}
						
						else if(dclass) 
							jQuery(item).find('a').addClass(dclass);
					}
					
				});
				
			}
			
		});
		
	});

})(jQuery);
