$(document).ready(function()
	{
		initRollover();
	}
);
function initRollover()
{
	var preLoad = [];
	$('img.rollover').each(function()
		{
			var src = $(this).attr('src');
			var fromIndex = src.indexOf('?');
			if(fromIndex == -1) {
				fromIndex = src.length;
			}
			var lastIndexOf = src.lastIndexOf('.', fromIndex);
			if(lastIndexOf != -1) {
				var newSrc = src.substr(0, lastIndexOf)+'_f2'+src.substr(lastIndexOf);
				preLoad.push(newSrc);
				$(this).hover(function()
					{
						$(this).attr('src', newSrc);
					}, function()
					{
						$(this).attr('src', src);
					}
				);

			}
		}
	);
	if(preLoad.length) {
		preLoadImagesArray(preLoad);
	}
}
function initProjectSwitcher(id)
{
	$('select[@name="'+id+'"]').each(function()
		{
			$(this).siblings('input[@type="submit"]').remove();
			$(this).change(function()
				{
					$(this).parents('form')[0].submit();
				}
			);
		}
	);
}
var fileSwitcher = {file:{},keys:[],currentKey:0,contentID:''}
function initFileSwitcher(contentID, switcherID, currentFile, files)
{
	if($('#'+switcherID).length && $('#'+contentID).length) {
		eval('fileSwitcher[\'files\'] = '+files+';');
		fileSwitcher['contentID'] = contentID;
		files = null;
		var preLoad = [];
		jQuery.each(fileSwitcher['files'], function()
			{
				if(this['id'] == currentFile) {
					fileSwitcher['currentKey'] = fileSwitcher['keys'].length;
				} else if(this['image']) {
					preLoad.push(this['image']);
				}
				fileSwitcher['keys'].push(this['id']);
			}
		);
		$('#'+switcherID).click(function(event)
			{
				var newKey = 0;
				if(fileSwitcher['currentKey'] < fileSwitcher['keys'].length-1) {
					newKey = fileSwitcher['currentKey']+1;
				}
				file = fileSwitcher['files'][fileSwitcher['keys'][newKey]];
				if(file['image']) {
					var node = jQuery("<img>").attr({src:file['image'],alt:file['alt'],title:file['alt']});
					if(file['width']) {
						$(node).attr('width', file['width']);
					}
					if(file['height']) {
						$(node).attr('height', file['height']);
					}
				} else if(file['flash']) {
					var node = file['alt'];
				}
				$('#'+fileSwitcher['contentID']).empty().append(node);
				if(file['flash']) {
					$('#'+fileSwitcher['contentID']).wrapInner('<div id="flash"></div>');
					$('#flash').flash({src: file['flash'], width: 475, height: 341,wmode:'transparent'});
				}
				fileSwitcher['currentKey'] = newKey;
				event.stopPropagation();
				event.preventDefault();
				return false;
			}
		);
		if(preLoad.length) {
			preLoadImagesArray(preLoad);
		}
	}
}
function preLoadImages()
{
	if(arguments.length) {
		preLoadImagesArray(arguments);
	}
}
function preLoadImagesArray(imgs)
{
	jQuery.each(imgs, function()
		{
			jQuery("<img>").attr('src', this);
		}
	);
}