new function($) {
  $.fn.setCursorPosition = function(pos) {
    if ($(this).get(0).setSelectionRange) {
      $(this).get(0).setSelectionRange(pos, pos);
    } else if ($(this).get(0).createTextRange) {
      var range = $(this).get(0).createTextRange();
      range.collapse(true);
      range.moveEnd('character', pos);
      range.moveStart('character', pos);
      range.select();
    }
  }
}(jQuery);

new function($) {
  $.fn.focusBlur = function(text) {
    $(this).focus(function(){
    	if($(this).val()==text)
    		$(this).addClass('focus').setCursorPosition(0);
    }).blur(function(){
    	if($(this).val()==text)
    		$(this).removeClass('focus');
    	else if ($(this).val()=='')
    		$(this).val(text);
    }).keydown(function(){
    	if($(this).val()==text)
    		$(this).removeClass('focus').val('');
    });
  }
}(jQuery);

jQuery(document).ready(function($){
	$('#email').focusBlur('your_email@somewhere.com');
	$('#name').focusBlur('Name');
	$('#mobile').focusBlur('Mobile');
	
	var addFields = $('#additional-fields');
	$('#subscribe-form').mouseover(function(event){
		event.preventDefault();
		addFields.slideDown(200);
	}).mouseleave(function(){
		if(!addFields.hasClass('show'))
			addFields.slideUp(200);
	});
	
	$('#subscribe-form input').focus(function(){
		addFields.addClass('show');
	}).blur(function(){
		addFields.removeClass('show');	
	});
});
