	var hideOnLoad = new Array('code', 'demo', 'auctionNudge', 'loading', 'formHelp', 'settings');
	var mouseX = 0;
	var mouseY = 0;
	$(document).ready(function() {
		$.each(hideOnLoad, function(key, value) {
			$('#' + value).hide();
		});
		$('#ebayID').focus();
		$('#demo').hide();
		$('legend').each(function(index) {
			$(this).replaceWith('<h3>' + $(this).text() + '</h3>');
		});
		$('#formHelp').load('help/help_help.html');
		$('#theme').change(function() {
			switch($('#theme').val()) {
				case '1' :
					$('#widthContainer').hide();
					$('#colsContainer').hide();  
					break;
				case '5' :
					$('#colsContainer').hide();  
					break;					
				default :
					$('#colsContainer').show(); 
					$('#widthContainer').show();
					break;
			}
		});
		$('#middle a img').hover(function(event) {
			$('#formHelp').html(' ');
			mouseX = event.pageX; 
			mouseY = event.pageY;
			$('#formHelp').load('help/' + event.target.id + '.html');
			$('#formHelp').css('top', mouseY + 5);
			$('#formHelp').css('left', mouseX + 5);
			$('#formHelp').show();
			return false;
		}, function(event) {
			//$('#formHelp').load('help/help_help.html');
			$('#formHelp').hide();
			return false;
		});
		$('#formGo').hover(function() {
			$('#formGo').attr('src', $('#formGo').attr('src').replace('off.gif', 'on.gif'));
		}, function() {
			$('#formGo').attr('src', $('#formGo').attr('src').replace('on.gif', 'off.gif'));
		});
		$('#formGo').click(function() {
			var checkField = $('#ebayID');
			if(checkField.val() == '') {
				$('#ebayID').focus();
				checkField.addClass('error')
				.prev('label').addClass('required-marker');
				return false;
			}else{
				checkField.removeClass('error')
				.prev('label').removeClass('required-marker');			
			}
			$('#formGo').attr('src', 'images/layout/button_refresh_off.gif');
			$('#settings').show();
			$('#loading').show();
			$.ajax({
				'url': 'build_url.php',
				'data': {
					'ebayID': $('#ebayID').val(),
					'type': $('input[name=type]:checked').val(),
					/*'type': $('#type').val(),*/
					'site': $('#site').val(),
					'cols': $('#cols').val(),
					'width': $('#width').val(),
					'limit': $('#limit').val(),
					'theme': $('#theme').val()
				},
				'dataType': 'json',
				'type': 'POST',
				'success': function(data) {
					$('#code').slideDown();
					$('#codeOut').val(data['js']);
					$('#demo').slideDown();
					$('#auctionNudge').load(data['url'] + '&output=raw').slideDown().ajaxStop(function() {
						$('#loading').hide();
					});
					return false;
				}
			});
			return false;
		});
	});
