$(document).ready(function() {
	var height = $(document).height() -1500;
	var position = $('#home').offset();
	$('#boc-bucket').css({'left' : position.left -160, 'top' : position.top +310});
	$('#boc-water').css({'left' : position.left -130, 'top' : position.top +486, 'height' : height});
	$('#bottle-for-change').css({'left' : position.left -200, 'top' : height +920});
	
	$(window).bind('resize', function() {
		var position = $('#home').offset();
		var height = $(document).height() -1500;
		$('#boc-bucket').css({'left' : position.left -160, 'top' : position.top +310});
		$('#boc-water').css({'left' : position.left -130, 'top' : position.top +486, 'height' : height});
		$('#bottle-for-change').css({'left' : position.left -200, 'top' : height +920});
	});
	
	$('a[href*=#]').click(function() {
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
    && location.hostname == this.hostname) {
      var $target = $(this.hash);
      $target = $target.length && $target
      || $('[name=' + this.hash.slice(1) +']');
      if ($target.length) {
        var targetOffset = $target.offset().top;
        $('html,body')
        .animate({scrollTop: targetOffset}, 1000);
       return false;
      }
    }
  });
  
  if (!$.browser.webkit) {
		$('input').placeholder();
	}
});

new function($) {
    $.fn.placeholder = function(settings) {
        settings = settings || {};
        var key = settings.dataKey || "placeholderValue";
        var attr = settings.attr || "placeholder";
        var className = settings.className || "placeholder";
        var values = settings.values || [];
        var block = settings.blockSubmit || false;
        var blank = settings.blankSubmit || false;
        var submit = settings.onSubmit || false;
        var value = settings.value || "";
        var position = settings.cursor_position || 0;

        
        return this.filter(":input").each(function(index) { 
            $.data(this, key, values[index] || $(this).attr(attr)); 
        }).each(function() {
            if ($.trim($(this).val()) === "")
                $(this).addClass(className).val($.data(this, key));
        }).focus(function() {
            if ($.trim($(this).val()) === $.data(this, key)) 
                $(this).removeClass(className).val(value)
                if ($.fn.setCursorPosition) {
                  $(this).setCursorPosition(position);
                }
        }).blur(function() {
            if ($.trim($(this).val()) === value)
                $(this).addClass(className).val($.data(this, key));
        }).each(function(index, elem) {
            if (block)
                new function(e) {
                    $(e.form).submit(function() {
                        return $.trim($(e).val()) != $.data(e, key)
                    });
                }(elem);
            else if (blank)
                new function(e) {
                    $(e.form).submit(function() {
                        if ($.trim($(e).val()) == $.data(e, key)) 
                            $(e).removeClass(className).val("");
                        return true;
                    });
                }(elem);
            else if (submit)
                new function(e) { $(e.form).submit(submit); }(elem);
        });
    };
    var setTextareaState = function(ev) {
		var $this = $(this), val = $this.val(), placeholder = $this.attr('placeholder');
		if (ev.type == 'mousedown' && val == placeholder ) {
			$this.val('');
		} else if (ev.type == 'mouseout' && val == '' && !!placeholder) {
			$this.val(plcaeholder);
		}
	};
}(jQuery);

$(function () {
	var setTextareaState = function(ev) {
		var $this = $(this), val = $this.val(), placeholder = $this.attr('placeholder');
		if (ev.type == 'mousedown' && val == placeholder ) {
			$this.val('');
		} else if (ev.type == 'mouseout' && val == '' && !!placeholder) {
			$this.val(placeholder);
		}
	};
	
	$('form textarea').live('mousedown', setTextareaState).live('mouseout', setTextareaState);
	
	$('textarea').each(function(){
		var placeholder = $(this).attr('placeholder');
		if (placeholder && $(this).val() == '') {
			$(this).val(placeholder);
		}
	});
});

