//Fancy navigation
$(document).ready(function(){
  var num = 0;
  $("#main-nav li").each(function(){
    num++;
    $(this).addClass('li-'+num);
	var child = $('<div></div>');
    $(this).prepend(child);
	if(!$(this).hasClass('active'))
    $(this).find("div").stop().animate({'opacity': '0'},1500);
  }).hover(function(){
    $(this).find("div").stop().animate({'opacity': '1'},500);
  }, function(){
	if(!$(this).hasClass('active'))
    $(this).find("div").stop().animate({'opacity': '0'},500);
  }).click(function(event){
	setActive($(this));
	event.preventDefault();
	var link = $(this).find("a");
	var full_url = link.attr('href');
	var parts = full_url.split("#");
	var trgt = parts[1];
	scrollTo(trgt);
  });
  
  $(".hbtn").each(function(){
    num++;
    $(this).addClass('li-'+num);
	var child = $('<div></div>');
    $(this).prepend(child);
	if(!$(this).hasClass('active'))
    $(this).find("div").stop().animate({'opacity': '0'},1500);
  }).hover(function(){
    $(this).find("div").stop().animate({'opacity': '1'},500);
  }, function(){
	if(!$(this).hasClass('active'))
    $(this).find("div").stop().animate({'opacity': '0'},500);
  }).click(function(event){
	event.preventDefault();
	var link = $(this);
	var full_url = link.attr('href');
	var parts = full_url.split("#");
	var trgt = parts[1];
	scrollTo(trgt);
  });
  
  $("#home h1").click(function(){
	scrollTo("webdesign");
  });
  
  
  function scrollTo(trgt) {
	var target_offset = $("#"+trgt).offset();
	var target_top = target_offset.top;
	if($.browser.opera){
	  $("html").animate({
		scrollTop:target_top
	  },500)
	  }else{
	  $("html,body").animate({
		scrollTop:target_top
	  },500)
	}
  }
  
  function setActive(a) {
	$("#main-nav li").removeClass('active');
	a.addClass('active');
	$("#main-nav li").each(function(){
		if($(this).hasClass('active'))
			$(this).find("div").stop().animate({'opacity': '1'},500);
		else
			$(this).find("div").stop().animate({'opacity': '0'},500);
	});
  }
  
  var targets = $(".target");
  var navButtons = $("#main-nav li");
  var lastPosition = $('html').scrollTop();
  function checkScroll() {
	var tar;
	var scrollTop = $(window).scrollTop();
	targets.each(function(){
		var currTop =$(this).offset().top;
		var offset = 227;
		if(currTop-offset <= scrollTop) {
			tar = $(this).attr('id');
		}
	});
	var activeButtons = $("#main-nav li.active");
	if(activeButtons.find('a').attr('href') != "#"+tar) {
		setActive($("#main-nav li a[href=#"+tar+"]").parent());
	};
  }

  $(window)
  .bind('scroll',
	function(e){
		checkScroll();
	}
  );

  checkScroll();

});

jQuery(function() {
	jQuery.support.placeholder = false;
	test = document.createElement('input');
	if('placeholder' in test) jQuery.support.placeholder = true;
});

$(function() {
	if(!$.support.placeholder) { 
		var active = document.activeElement;
		$(':text, textarea').focus(function () {
			if ($(this).attr('placeholder') != '' && $(this).val() == $(this).attr('placeholder')) {
				$(this).val('').removeClass('hasPlaceholder');
			}
		}).blur(function () {
			if ($(this).attr('placeholder') != '' && ($(this).val() == '' || $(this).val() == $(this).attr('placeholder'))) {
				$(this).val($(this).attr('placeholder')).addClass('hasPlaceholder');
			}
		});
		
		
		$(':text, textarea').blur();
		$(active).focus();
		$('form').submit(function () {
			$(this).find('.hasPlaceholder').each(function() { $(this).val(''); });
		});
	}
});


