;$(document).ready(function()
{
	/**
	* Initialize an array of sites with rotating graphics
	* @Todo Make SURE to create the site_rotator directory when adding new entries!
	*/
	var sites_with_rotating_graphics = ['rdschool', 'athleticgateway'];
	
	// Temporary fix for IE7 caching (disable this functionality for all sites)
	var sites_with_rotating_graphics = new Array;
	$.get('../site_resources/php/getSiteRootName.php', function(site)
	{
		// Make sure there is a valid resposne and the site is not within the create or edit mode of the system
		if (site && site != 'cms' && site != 'tmp')
		{
			// Check if the current site is in the rotating list
			for (i = 0; i < sites_with_rotating_graphics.length; i++)
			{
				if (sites_with_rotating_graphics[i] == site)
				{
					// Get the current title-banners image
					var image = $('#main .title-banners .visual').find('img').attr('src');
					var path_parts = image.split('/');
					
					// Loop through all of the directory parts in the image path
					for (i = 0; i < path_parts.length; i++)
					{
						// We don't care about relative directories
						if (path_parts[i] == '.' || path_parts[i] == '..') continue;
						
						// Look for the header images directory
						if (path_parts[i] == 'header_images')
						{
							// Check if the next directory part is NOT an image (This site has a sub-directory image)
							if (!path_parts[i+1].match(/.jpg/))
							{
								// Prevent the rotator from being added
								return false;
							}
						}
					}
					
					// Remove the default image
					$('#main .title-banners .visual img')
						.remove()
					;
					
					// Append the rotator script to the header
					var rotator = '<scr' + 'ipt type="text/javascript" src="../site_resources/templates/standard/header_images/' + site + '_rotator/rotator.js"><\/scr' + 'ipt>';
					$('head').append(rotator);
					return true;
				}
			}
		}
		// Show the default image
		else
		{
			$('#main .title-banners .visual img').fadeIn(900);
		}
	});
});

