$(document).ready(function()
      {

//datePicker
$('.date-pick').datePicker({startDate:'01/01/2000',clickInput:true,createButton:false})


$('input[type="text"],textarea').toggleVal('jq-active');




$('#text').find('p.hide').hide();
//$('#text + p.hide').hide();

$('#text a.show').click(function(){
			$('p.hide').toggle();//show()
			$(this).toggleClass("show-active");
			return false;
							});



$('#side-nav>ul>li>ul:not(.alwaysVisible)').hide();

 $('#side-nav>ul>li:not(.alwaysVisible)').hover(

	function()
	        {
            $(this).find('ul:hidden').slideDown('slow');
           },
           function()
             {
              $(this).find('ul:visible').slideUp('slow');
             }

			   );




}
     );


jQuery.fn.toggleVal = function(focusClass) {
	this.each(function() {
		$(this).focus(function() {

			if($(this).val() == this.defaultValue) { $(this).val(''); }


			if(focusClass) { $(this).addClass(focusClass); }
		}).blur(function() {

			if($(this).val() == '') { $(this).val(this.defaultValue); }


			if(focusClass) { $(this).removeClass(focusClass); }
		});
	});


	//googlemapcode
	if(document.getElementById("map")){

		setTimeout(function(){
			var longitude = document.getElementById("longitude").value;
			var latitude =  document.getElementById("latitude").value;



	        var map = new GMap2(document.getElementById("map"));
	        map.setCenter(new GLatLng(latitude, longitude), 15);
	  		map.addOverlay(new GMarker(new GLatLng(latitude, longitude)	));
	  		map.addControl(new GSmallMapControl());
	 		map.addControl(new GMapTypeControl());
		},500);
	}

	if(document.getElementById("faqs")){
		var faqsList = document.getElementById("faqs");
		var faqsListDTs = faqsList.getElementsByTagName("dt");

		//hide all
		$('#faqs dd').hide();

			for(var i=0; i < faqsListDTs.length; i++){
			$('#faqs dt:eq('+i+')').bind(
				'click',

				{
					index: i
				},

				function(event){
					$('#faqs dd:eq('+event.data.index+')').toggle();
				}

			);

		}

	}
}




var createInvoiceBox = function(){

if( $(".invoiceFields:last input[value='']").length == 0){
	$(".invoiceFields:first").clone().insertBefore("#createInvoiceBoxLink");

	$(".invoiceFields:last input").attr("value","");
	$(".invoiceFields:last .invoiceFieldName").html("Invoice "+$(".invoiceFields").length);

	$('.invoiceFields:last .date-pick').datePicker({startDate:'01/01/2000',clickInput:true,createButton:false})
}else{
	alert('You must enter all the details on previous invoices before you can add another');
}

};