$(document).ready(function(){
	$("#accordion1").msAccordion({defaultid:0, autodelay:6});


	$(".main_nav li").hover(
		 function(){
			 if($(this).children('div.dropper_nav').is(':hidden'))
			 	$(this).children('div.dropper_nav').show();
		 }, 
		 function (){
			 if(!$(this).children('div.dropper_nav').is(':hidden'))
			 	$(this).children('div.dropper_nav').hide();
	});
		  
		  
	$('div.dropper_nav ul li:first-child').css('background','none');
	
		$("#submitForm").click(function() {
			
			checkFormVal();
		    showLoading('#quoteForm');
			$.post('includes/formprocess.php',
                    $("#sendMail").serialize(),
                    function(data){
                        processData(data);
                    }
                    );
		});
	var page = 1;
	showLoading('#completedProjects');
	$.post('includes/completedprojects.php',{page:page},function(data) {
		completedProject(data);
	});

	$('ul.pagging li').click(function() {
		showLoading('#completedProjects');
		var page = $(this).text();
		$.post('includes/completedprojects.php',{page:page},function(data) {
		completedProject(data);
	});
	});
	
 });


/********************				Define Functions 	*************************************/ 
 function processData(data){
    $('#quoteForm').html(data);
 }
 
 function showLoading(divId){
    $(divId).addClass('inactiveForm');
    $(divId).append('<img class ="loader" src ="images/interface/loader.gif">');
 }
 
 function checkFormVal() {
				if($('#inputName').val() ==''||$('#inputName').val() =='Name...') {
					alert("Please enter your name.");
					exit;
				}
				if($('#inputEmail').val() ==''||$('#inputEmail').val() =='Email...') {
					alert("Please enter your email address.");
					exit;
				}
				var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
				var email = $('#inputEmail').val();
				if(reg.test(email)==false){
					alert("Please enter a valid email address.");
					exit;
				}
				if($('#inputPhone').val() ==''||$('#inputPhone').val() =='Phone...') {
					alert("Please enter your phone number.");
					exit;
				}
				if($('#inputMessage').val() ==''||$('#inputMessage').val() =='Message') {
					alert("Please enter a valid message.");
					exit;
				}				

			}

function completedProject(data) {
	$('#completedProjects').html(data);
}




/**************************************************** not good funtions but works ******************************************/
$(document).ready(function(){
$(".flip1").click(function(){
	$(".panel1").slideToggle("slow");
  });
});

$(document).ready(function(){
$(".flip2").click(function(){
	$(".panel2").slideToggle("slow");
  });
});

$(document).ready(function(){
$(".flip3").click(function(){
	$(".panel3").slideToggle("slow");
  });
});

$(document).ready(function(){
$(".flip4").click(function(){
	$(".panel4").slideToggle("slow");
  });
});
