$(document).ready(function () {
					   

	// set draggable objects
	
	$('#window, #toolbar, #layers, #swatches').draggable();	
	
	
	
	// menu animations
	
	$('ul#menu li a').click(function() {
	
		var page = '#' + $(this).attr('name');
		
		$('#content .page').hide();
		
		$('#content '+page).show();
	
		$('ul#menu li a').removeClass('current');
	
		$(this).addClass('current');
		
		return false;
	
	});
	
	// css correction on menu
	
	$('ul#menu li:last').css({ 'border-bottom' : 'none' });
	
	
	
	// set up swatch colours based of their title tag
	
	$('#colours a').each(function() { 
	
		var colour = $(this).attr('href');
		
		$(this).css({ 'background-color' : colour });
	
	});
	
	// change the background colour of the body when the swatches are clicked
	
	$('#colours a').click(function() {
	
		var colour = $(this).attr('href');
		
		$('body').css({ 'background-image' : 'none' });
		
		$('body').animate({ backgroundColor : colour }, 500);
	
		return false;
	
	});
	
	
	// set up swatch backgrouns
	
	$('#patterns a').each(function() { 
	
		var pattern = $(this).attr('href');
		
		var url = 'url(' + pattern + ')';

		$(this).css({ 'background-image' : url });
	
	});
	
	// change background image of body when images are clicked
	
	$('#patterns a').click(function() { 
	
		var pattern = $(this).attr('href');
		
		var url = 'url(' + pattern + ')';

		$('body').css({ 'background-image' : url, 'background-color' : '#fff' });
		
		return false;
	
	});
	
	
	// simple gallery script
	
	$('#portfolio .right-column a').click(function(){
	
		var img = new Image();
  
  		var src = $(this).attr('href');

  		
  		$('#portfolio .left-column img').fadeOut('fast', function() {  
  		
  			$('#portfolio .left-column img').remove();
  	
  			$(img).load(function() {
	
    				$(this).hide();
    
      			$('#loader').append(this);

     			$(this).fadeIn();
     	
    			}).error(function () {
      
    			}).attr('src', src);
    			
    		});
	
		return false;
	
	}); 
	
	
	// contact form
	
	function validate(formData, jqForm, options) { 

    		for (var i=0; i < formData.length; i++) { 
    			if (!formData[i].value) { 
          		alert('Please fill in all the fields'); 
            		return false; 
        		} 
    		} 
    		
    		$("#contact-form").validate({
 			rules: {
    			email: {
      			required: true,
      			email: true
    				}
  			}
		});
		
		if($("#contact-form").valid() == false) {
		
			return false;
		
		} else {
		
			return true;
		
		}
    		
	}
	
	function form_complete() {
		
		alert('Thank you! You form has been sent.');
		
	}
	
	
	$('#contact-form').ajaxForm({ 
	
		beforeSubmit: validate,
		success:	form_complete,
		clearForm: true
	
	});
	
	
});
