$(document).ready(function() {
	// Rounded corners on item list images
	$('.item-list li .item-image, .item-image-list li .item-image, .small-item-image-list li .small-item-image').corner('5px');
	
	// Move legends to H2s
	$('legend').each(function() {
		$(this).after('<h2>' + $(this).html() + '</h2>');  
	});
	
	// Flash Messages
	$('#message').corner('bottom 1em').append('<div class="message-close"><a href="#">&nbsp;</a></div>');
	$('.message-close').corner('1em');
	$('.message-close a').click(function() {
		$(this).parent().parent().slideUp();
	});
	
	// External links 
	$("a[rel='external']").click(function() {
		this.target = "_blank";
	});
	// Flash Files
	$('.flash').each(function() {
		var config = {};
		$(this).find('a').each(function() {
			// TODO: check if url contains swf
			config.swf = $(this).attr('href');
			var width = jQuery.url.setUrl(config.swf).param("width");
			var height = jQuery.url.setUrl(config.swf).param("height");
			if (width) {
				config.width = width;	
			}
			if (height) {
				config.height = height;	
			}
		});
		//alert(config.swf);
		$(this).html('').flash(config);
	});
	
	// Colorbox
	$('.colorbox').colorbox();
	
	// Progress Bars
	$('.progress-bar').each(function() {
		var value = $(this).html();
		var insert = '&nbsp;';
		var post = value;
		var change = false;
		if (value.indexOf('%')) {
			value = value.replace('%', '');
		}
		$(this).html('');
		if (value > 75) {
			change = true;
		}
		if (value > 100) {
			value = 100;	
		}
		value = value + '%';
		if ( change ) {
			insert = value;
			post = '&nbsp;';
		}
		$(this).prepend('<div class="progress-completed">' + insert + '</div>' + post).find('.progress-completed').css('width', value);
	});
	//*/
});
