/***** 1: Card Flip *****/
$(document).ready(function () {
    $('#cardFlip li div.back').hide().css('left', 0);
    function mySideChange(front) {
        if (front) {
            $(this).parent().find('div.front').show();
            $(this).parent().find('div.back').hide();
            
        } else {
            $(this).parent().find('div.front').hide();
            $(this).parent().find('div.back').show();
        }
    }
    $('#cardFlip li').hover(
        function () {
            $(this).find('div').stop().rotate3Di('flip', 400, {direction: 'clockwise', sideChange: mySideChange});
        },
        function () {
            $(this).find('div').stop().rotate3Di('unflip', 400, {sideChange: mySideChange});
        }
    );
}); 
/***** 1: END *****/

/***** 2: Scroll To Top *****/
	$(function () {

		/* set variables locally for increased performance */
		var scroll_timer;
		var displayed = false;
		var $message = $('#message');
		var $window = $(window);
		var top = $(document.body).children(0).position().top;

		/* react to scroll event on window */
		$window.scroll(function () {
			window.clearTimeout(scroll_timer);
			scroll_timer = window.setTimeout(function () { // use a timer for performance
				if($window.scrollTop() <= top) // hide if at the top of the page
				{
					displayed = false;
					$message.fadeOut(500);
				}
				else if(displayed == false) // show if scrolling down
				{
					displayed = true;
					$message.stop(true, true).fadeIn(500).click(function () { $message.fadeOut(500); });
				}
			}, 100);
		});
		$('#top-link').click(function(e) { 
			e.preventDefault();
			$.scrollTo(0,300); 
		   });
	});
/***** 2: END *****/


/***** 3: Lable Hide *****/
function initOverLabels () {
  if (!document.getElementById) return;  	
  var labels, id, field;
  labels = document.getElementsByTagName('label');
  for (var i = 0; i < labels.length; i++) {
    if (labels[i].className == 'overlabel') {
      id = labels[i].htmlFor || labels[i].getAttribute('for');
      if (!id || !(field = document.getElementById(id))) {
        continue;
      }
      labels[i].className = 'overlabel-apply';
      if (field.value !== '') {
        hideLabel(field.getAttribute('id'), true);
      }
      field.onfocus = function () {
        hideLabel(this.getAttribute('id'), true);
      };
      field.onblur = function () {
        if (this.value === '') {
          hideLabel(this.getAttribute('id'), false);
        }
      };
      labels[i].onclick = function () {
        var id, field;
        id = this.getAttribute('for');
        if (id && (field = document.getElementById(id))) {
          field.focus();
        }
      };
    }
  }
};
function hideLabel (field_id, hide) {
  var field_for;
  var labels = document.getElementsByTagName('label');
  for (var i = 0; i < labels.length; i++) {
    field_for = labels[i].htmlFor || labels[i].getAttribute('for');
    if (field_for == field_id) {
      labels[i].style.textIndent = (hide) ? '-1000px' : '0px';
      return true;
    }
  }
}
window.onload = function () {
  setTimeout(initOverLabels, 50);
};
/***** 3: END *****/

