(function(){
	placeholder();
	scro();
	form();
})();
function placeholder(){
	if(!('placeholder' in document.createElement('input'))){
		$("input[placeholder], textarea[placeholder]").each(function(){
    		if($(this).attr('type') !== 'password')
    			$(this).val( $(this).attr("placeholder") );
		});
		$("input[placeholder], textarea[placeholder]").focus(function() {
            if($(this).val() == $(this).attr("placeholder"))
                $(this).val('');
        }).blur(function(){
            if($(this).val() == "")
            	if($(this).attr('type') !== 'password')
                	$(this).val($(this).attr("placeholder"));
        });
	}
}
function scro(){
  function filterPath(string) {
  return string
    .replace(/^\//,'')
    .replace(/(index|default).[a-zA-Z]{3,4}$/,'')
    .replace(/\/$/,'');
  }
  var locationPath = filterPath(location.pathname);
  var scrollElem = scrollableElement('html', 'body');
  $('a[href*=#]').each(function() {
    var thisPath = filterPath(this.pathname) || locationPath;
    if (  locationPath == thisPath
    && (location.hostname == this.hostname || !this.hostname)
    && this.hash.replace(/#/,'') ) {
      var $target = $(this.hash), target = this.hash;
      if (target) {
        var targetOffset = $target.offset().top;
        $(this).click(function(event) {
          event.preventDefault();
          $(scrollElem).animate({scrollTop: targetOffset}, 400, function() {
            location.hash = target;
          });
        });
      }
    }
  });
  function scrollableElement(els){
    for (var i = 0, argLength = arguments.length; i <argLength; i++) {
      var el = arguments[i],
          $scrollElement = $(el);
      if ($scrollElement.scrollTop()> 0) {
        return el;
      } else {
        $scrollElement.scrollTop(1);
        var isScrollable = $scrollElement.scrollTop()> 0;
        $scrollElement.scrollTop(0);
        if (isScrollable) {
          return el;
        }
      }
    }
    return [];
  }
}
function form(){
	$('#connect button').click(function(e){
		e.preventDefault();
		$('.error').removeClass('error');
		var data = $(this).parent().serialize();
		if($('input[name="name"]').val() == '' || $('input[name="email"]').val() == '' || $('textarea').val() == ''){
			return;
		}
		$.ajax({
			type: 'post',
			cache: false,
			url: 'index.php',
			data: data
		}).done(function(response){
			console.log(response);
			if(response == '0'){
				$('input[name="email"]').addClass('error');
			}else if(response == '-1'){
				var str = '<p>There was an error sending. Please try again</p>';
				$('#connect form').append(str).delay(1200).remove('#connect form p');
			}else{
				$('#connect form').slideUp();
				var str = '<p class="success">Thanks! Your message has been sent. I will be in touch shortly</p>';
				$(str).insertAfter($('#connect form'));
			}
		});
	});
}
window.log = function(){
  log.history = log.history || [];
  log.history.push(arguments);
  arguments.callee = arguments.callee.caller;  
  if(this.console) console.log( Array.prototype.slice.call(arguments) );
};
(function(b){function c(){}for(var d="assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,markTimeline,profile,profileEnd,time,timeEnd,trace,warn".split(","),a;a=d.pop();)b[a]=b[a]||c})(window.console=window.console||{});
