// JavaScript Document

$(document).ready(function() {
		var navitems = $("a[id^=navitem_]");
		jQuery.each(navitems, function() {
			$(this).click(function() {
				var id = $(this).attr('id').replace('navitem_','');
				showContentSection(id);
				resetCurrentNav();
				$(this).parent().attr('class', 'current');
		   	});
		});
		var h2 = $('h2');
		jQuery.each(h2, function() { 
			$(this).click(function() {
				resetServices();
				$(this).next().show() 
			}); 
		}); 
		
		var services_list_items = $('li[class=services_offered_list]')
		jQuery.each(services_list_items, function() { 
				$(this).click(function() {
				showContentSection('services');
				resetCurrentNav();
				$('#navitem_services').parent().attr('class', 'current');
	});
				

		}); 
});

function contactFormDialog(){
	//popup dialog
		$('#contact-form-dialog').dialog('destroy');
		$('#contact-form-dialog').dialog({
			autoOpen: false, 
			bgiframe: true,
			modal: true,
			height: '325',
			width: '365',
			buttons: {
				"Exit": function() {
					$(this).dialog("close");
				},
				"Submit": function() {
					 $('#contactForm').submit()
				}
			 }
		});
		$('#contact-form-dialog').dialog('open');
 }
 
function submitContactInfo(){
	$.ajax({
   type: "GET",
   url: "http://www.worshamweb.com/contact-info.php",
   data: "name=" + $('#name').val() + "&phone=" + $('#phone').val() + "&email=" + $('#email').val() + "&comments=" + $('#comments').val(),
   success: function(){
      showContentSection('contact_success');
   },
   fail: function(){
	  showContentSection('contact_fail');
   }
  
   
 });
	
}

function resetServices(){
	var h2 = $('h2');
		jQuery.each(h2, function() { 
			$(this).next().hide();
		});
}

function resetCurrentNav(){
	var navListItem = $("li[name=navitem]");
		jQuery.each(navListItem, function() {
			$(this).attr('class', '');
	});
}

function hideContentSections(){
	var content_sections = $("div[class=content_section]");
	jQuery.each(content_sections, function() {
			$(this).hide('fast')
	});
}

function showContentSection(id){
	hideContentSections();
	if($.browser.msie){
		$('#' + id).show("slow");
	}else{
		var rnd = $.randomBetween(1, 6);
		switch(rnd){
			case 1:
			  $('#' + id).show("slow");
			  break;
			case 2:
			  $('#' + id).show('slide',{},700);
			  break;
			case 3:
			  $('#' + id).fadeIn("slow");
			  break;
			case 4:
			  $('#' + id).show('bounce',{},600);
			  break;
			case 5:
			  $('#' + id).show('blind',{},700);
			  break;
			default:
				$('#' + id).show("slow");
		}
	}
}
