(function($){
  $(document).ready(function(){ 

$("#formButton" ).button();

$(window).load(function() {
        $('#slider').nivoSlider({
		controlNav:false,
		pauseTime:5000,
		directionNav:false
		});

			/* form layout */
			$('input[type="text"],textarea').addClass("idleField");
       		$('input[type="text"],textarea').focus(function() {
       			$(this).removeClass("idleField").addClass("focusField");
    		    if (this.value == this.defaultValue){ 
    		    	this.value = '';
				}
				if(this.value != this.defaultValue){
	    			this.select();
	    		}
    		});
    		$('input[type="text"],textarea').blur(function() {
    			$(this).removeClass("focusField").addClass("idleField");
    		    if ($.trim(this.value) == ''){
			    	this.value = (this.defaultValue ? this.defaultValue : '');
				}
    		});
		
		// icons 
		//hover states on the static widgets
		$('#dialog_link, ul#icons li').hover(
			function() { $(this).addClass('ui-state-hover'); }, 
			function() { $(this).removeClass('ui-state-hover'); }
		);
		////////////////////////////////////////////////////////////////
		//front page form
			$("#fpForm").validate({
			
			rules: {
				Name:{
				required: true	
				},
				Email:{
				required: true,
				email: true	
				},
				Query:{
				required: true
				},
				captcha:{
					required:true,
					remote:{
						url:"captcha.php",
						async:false,
						type:"POST"	
					}
				}
			},
			messages:{
				Name: "Please enter your name<br />",
				Email: "Please enter a valid email address"
			},
			   errorPlacement: function (error, element) { 
                               error.insertBefore(element);  
                             },
			
			submitHandler: function() {
				$("#fpForm").hide();
				$("#fpFormDone").show();
				
				var str = $("form").serialize();
				
				$.ajax({
						type: "POST",
						url: "mlform.php",
						cache: false,
						data: str,
						success: function(result) {
						$('p#SuccessMessage').html(result);
						},
						error: function(){
							alert("error!");
						}
						});
			}
		});

		
		////////////////////////////////////////////////////////////////
		//paginate
				
				$('ul#items').easyPaginate({
					step:6
				});
				
				$("a[rel='popupSlideShow']").colorbox({slideshow:true});
				$("a[rel='popupImage']").colorbox({transition:"none",  height:"95%"});
				$(".popupPage").colorbox({iframe:true, innerWidth:950, innerHeight:"60%"});

		///////////////////////////////////////////////////////////////	
				$('#scroll').jScrollPane({
				showArrows: true	
				});

	});
});
})(jQuery);
