
jQuery.fn.center = function(loaded) {
    var obj = this;
    body_width = parseInt($(window).width());
    body_height = parseInt($(window).height());
    block_width = parseInt(obj.width());
    block_height = parseInt(obj.height());
    
    left_position = parseInt((body_width/2) - (block_width/2)  + $(window).scrollLeft());
    if (body_width < block_width) { left_position = 0 };
    top_position = parseInt((body_height/2) - (block_height/2) + $(window).scrollTop());
    if (body_height < block_height) { top_position = 0 };
    
    if(!loaded) {
        
        obj.css({'position': 'absolute'});
        obj.css({'left': left_position, 'top': top_position});
        $(window).bind('resize', function() { 
            obj.center(!loaded);
        });
        $(window).bind('scroll', function() { 
            obj.center(!loaded);
        });
        
    } else {
        obj.stop();
        obj.css({'position': 'absolute'});
        obj.animate({'left': left_position, 'top': top_position}, 200, 'linear');
    }
}

Cufon.replace('.content2 h5', { fontFamily : 'ITC Lubalin Graph' });

$(function() {

	$.preloadCssImages();
	$(document).pngFix(); 

	$('#content').center();
	
	$('.blink')
		.focus(function(){
			$(this).parent().addClass('code-field-active');
		})
		.blur(function(){
			if( $(this).val() == '' )
				$(this).parent().removeClass('code-field-active');
		})




	// prepare Options Object 
	var options = { 
		dataType:  'json',
		beforeSubmit: validate,
		success:   processJson
	}; 
	 
	// pass options to ajaxForm 
	$('#entryForm').ajaxForm(options);
	
 
    function processJson(response) { 
    	// 'data' is the json object returned from the server
    	
   		if(response.result){
   			$('body').html(response.html);
   			$('#content').center();
   		}
   		else{
   			alert(response.message);
   		}
   		
	} 
	
	
	function validate(formData, jqForm, options){
		
		errorFound = false;
		
		$('.content2 form .req').each(function () {
			
			if ($(this).val() == '') {
				alert('All required fields must be specified.');
				errorFound = true;
				return false;
			}

		});
		
		if(!errorFound){
			if ($('#check1').attr('checked') == false) {
				alert('You must confirm that you have read the official rules before proceeding.');
				errorFound = true;
				return false;
			}
		}
		
		if(!errorFound){
			if ($('#email').val() != $('#email2').val()) {
				alert('Your email address entries do not match.');
				errorFound = true;
				return false;
			}
		}
		
		//alert( "returning " + !errorFound);
		return !errorFound;
	}
 

	
	
});













