$(document).ready(function(){
$('.error').hide();			    
anchorclicked = "";	
					
$(".anchorlink").click(function(event){
			
			//var origcolour = $(this).css("background-color");
				
	        //prevent the default action for the click event
	        event.preventDefault();
	 
	        //get the full url - like mysitecom/index.htm#home
	        var full_url = this.href;
	 
	        //split the url by # and get the anchor target name - home in mysitecom/index.htm#home
	        var parts = full_url.split("#");
	        var trgt = parts[1];
	 
	        //get the top offset of the target anchor
	        var target_offset = $("#"+trgt).offset();
	        var target_top = target_offset.top - 50;
	 
	        //goto that anchor by setting the body scroll top to anchor top
	        $('html, body').animate({scrollTop:target_top}, 500);
			
			$("#nav-list a").removeClass("active");
			
			$(this).addClass("active");
			
       		//var colortext = "#fff";
      		//$(this).css("color", colortext).css("background-color",origcolour);
			
			anchorclicked = $(this).attr("id");
			//alert(anchorclicked);
			
	
	
	    });
$("#nav-list a").hover(
	
	function(){
		//alert(anchorclicked);
		//if (anchorclicked == $(this).attr("id")){
			//alert("Do nothing");
		//}else{
			//var color = $(this).css("color");
       		//var bgcolor = "#fff";
      		//$(this).css("color", bgcolor).css("background-color",color);
			$(this).addClass("active");
		//}
		
	},
	function(){
		if (anchorclicked == $(this).attr("id")){
			//alert("Do nothing");
		}else{
			//var color = $(this).css("color");
			//var bgcolor = $(this).css("background-color");
      		//$(this).css("color", bgcolor).css("background-color","");
			$(this).removeClass("active");
		}
		
	}
);
$("#content a").hover(
	
	function(){
			var color = $(this).css("color");
       		var bgcolor = "#fff";
      		$(this).css("color", bgcolor).css("background-color",color);
	},
	function(){
			var color = $(this).css("color");
			var bgcolor = $(this).css("background-color");
      		$(this).css("color", bgcolor).css("background-color","");
	}
);



$("a[rel]").overlay({ 
		expose: '#FFF',
        onBeforeLoad: function() { 
            var wrap = this.getContent().find(".contentWrap");  
            wrap.load(this.getTrigger().attr("href"));
        },
		onLoad: function() { 
        $("#images").scrollable({size: 1, clickable: true}).navigator();
		 $("#nav").fadeOut("slow");
		 $(".navi").animate({ 
        top: "-=30px",
      }, 1000 );
		 $(".navi").fadeIn("slow");
		 $("#clicker").click(function () {
      		$(".info").slideToggle("fast");
	  		$("#indicator").text($("#indicator").text() == 'Show project info' ? 'Hide project info' : 'Show project info');
    		return false;
    	});
    	},
		onClose: function() { 
		 $("#nav").fadeIn("slow");
		 $("#example-slide").animate({opacity: 1},400);
		 
    	}
 
    }); 
$(".infolink").overlay({ 		   
		expose: '#FFF',
        onBeforeLoad: function() { 
            var wrap = this.getContent().find(".contentWrap");  
            wrap.load(this.getTrigger().attr("href"));
        },
		onLoad: function() { 
        		 $("#nav").fadeOut("slow");
    	},
		onClose: function() { 
		 $("#nav").fadeIn("slow");
    	}
 
    }); 



$("#changeText").live('click', function(){ 
 
        var url = $(this).attr("href"); 
		//alert(url);
 
        $("#content-overlay").load(url, {var1:Math.random()*99999}); 
                 
       // $('html,body').animate({scrollTop: 10}, 1000, 'swing'); 
                 
        return false; 
    }); 

$("#changeProfile").live('click', function(){ 
 
        var url = $(this).attr("href"); 
		//alert(url);
        $("#content-overlay").load(url, {var1:Math.random()*99999}, function(){
			$("#images").scrollable({size: 1, clickable: true}).navigator();
			 $(".navi").animate({ 
        top: "-=30px",
      }, 1000 );
		 $(".navi").fadeIn("slow");
			$("#clicker").click(function () {
      		$(".info").slideToggle("fast");
	  		$("#indicator").text($("#indicator").text() == '+' ? '-' : '+');
    		return false;
    	});
										   });
        //
       // $('html,body').animate({scrollTop: 10}, 1000, 'swing'); 
                 
        return false; 
    }); 

$(".close").click(function(event){	
	$("#content-overlay").unload();
});	

$('#home').bind('inview', function (event, visible) {
  if (visible == true) {
    $("#Home-Link").addClass("active");
  } else {
    $("#Home-Link").removeClass("active");
  }
});
$('#about').bind('inview', function (event, visible) {
  if (visible == true) {
    $("#About-Link").addClass("active");
  } else {
    $("#About-Link").removeClass("active");
  }
});
$('#graphic-design').bind('inview', function (event, visible) {
  if (visible == true) {
    $("#Graphic-Design-Link").addClass("active");
  } else {
    $("#Graphic-Design-Link").removeClass("active");
  }
});
$('#web-design').bind('inview', function (event, visible) {
  if (visible == true) {
    $("#Web-Design-Link").addClass("active");
  } else {
    $("#Web-Design-Link").removeClass("active");
  }
});
$('#testimonials').bind('inview', function (event, visible) {
  if (visible == true) {
    $("#Testimonials-Link").addClass("active");
  } else {
    $("#Testimonials-Link").removeClass("active");
  }
});
$('#contact').bind('inview', function (event, visible) {
  if (visible == true) {
    $("#Contact-Link").addClass("active");
  } else {
    $("#Contact-Link").removeClass("active");
  }
});
   
   $('input.input-default').inputDefault();

   
   
   $(".button").click(function() {
      // validate and process form here

      $('.error').hide();
  	  var name = $.URLEncode($("#fld_name").val());
  		if ((name == ""), (name == "Your name")) {
        $("label#name_error").show();
        $("input#fld_name").focus();
        return false;
      }
  		var email = $.URLEncode($("#fld_email").val());
  		if ((email == ""), (email == "Your email address")) {
        $("label#email_error").show();
        $("input#fld_email").focus();
        return false;
      }
  		var phone = $.URLEncode($("#fld_telephone").val());
  		if ((phone == ""), (phone == "Your telephone number")) {
        $("label#phone_error").show();
        $("input#fld_telephone").focus();
        return false;
      }
	  if ($('#fld_optin').attr('checked')) {
	 	var optin = "True";
	 	} else {
		 var optin = "False";
	 	}

	  var comments = $.URLEncode($("#fld_enquiry").val());
var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone + '&comments=' + comments + '&optin=' + optin + '&submit=true';
  //alert (dataString);return false;
  $.ajax({
    type: "POST",
    url: "submit-form.asp",
    data: dataString,
    success: function() {
      $('#contact-form').html("<div id='message'></div>");
      $('#message').html("<h2>Contact Form Submitted!</h2>")
      .append("<p>We will be in touch soon.</p>")
      .hide()
      .fadeIn(1500);
	  var target_offset = $("#contact-form").offset();
	  var target_top = target_offset.top - 50;
	        //goto that anchor by setting the body scroll top to anchor top
	        $('html, body').animate({scrollTop:target_top}, 500);
    }
    });
  });
   

});

