$(document).ready(function() {
	
	 $("a.fancy").fancybox({
    
        'frameWidth': 620, 
        'frameHeight':  320,
		'titleShow': false,
		'overlayColor':	'#eee',
		'overlayOpacity':	0.5
		
    	 
    })					
				

    
    $("a.website").fancybox({
    
        'frameWidth': 620, 
        'frameHeight':  320
    })
	
	
	// login functionality
	
	$('#login').fadeOut(200);
	
	$("#dealer").toggle(
		function () { $('#login').fadeIn(100) },					  
		function () { $('#login').fadeOut(200) } 
	);
	
	
	
	var v = jQuery("#login_form").validate({
			submitHandler: function(form) {
				
				$('#response').html('<div id="loadcenter"><p>Loading...</p><div class="loading" id="loading"><div></div></div></div>');
				$().showLoading();
							
				/*var opts = {
					success: function(data) {
						
						if(data == '1')
							location.reload(true);

					
						$('#response').append(data);
					}
				};
				
				jQuery(form).ajaxSubmit(opts);
				*/
	
				
				
				
				jQuery(form).ajaxSubmit({
					target: '#response', 
                	//beforeSubmit: showRequest, 
                	success: result 
				});
				
				
			}
		});
 
 
 
 
	$("#pricing_btn").toggle(
		function () { $('#pricing_panel').show(200) },					  
		function () { $('#pricing_panel').hide(300) } 
	);
 
	
	
	
	
	
	
	/*
	 * Loader progress
	 */
	var loadingTimer,loadingFrame = 1; 
	 
	$.fn.animateLoading = function() {
		if (!$("#loading").is(':visible')){
			clearInterval(loadingTimer);
			return;
		}

		$("#loading > div").css('top', (loadingFrame * -40) + 'px');

		loadingFrame = (loadingFrame + 1) % 12;
	};

	$.fn.showLoading = function() {
		clearInterval(loadingTimer);

		var pos = $("#response").width();
		$("#loading").show();
		
		loadingTimer = setInterval($().animateLoading, 66);
	};
	
	
	
});


function showRequest(formData, jqForm, options) { 
        var queryString = $.param(formData); 
        alert('About to submit: \n\n' + queryString); 
        return true; 
} 

function showResponse(responseText, statusText) { 
        alert('status:' + statusText + '\n\nresponseText: \n' + responseText + '\n\nThe output div should have already been updated with the responseText'); 
        return false; 
} 

function result(responseText) {
	if(responseText == 'Login Successful')
		location.reload(true);
							
	
	
}

