// JavaScript Document

$(function() {

/*Auto Grow */
$('.input-textarea textarea').elastic();  

/* Watermarks */
$('.input-text, .input-textarea').each(function() {
	var $this = $(this);
	$this.find(':input').watermark( $this.find('label').text().replace(/\*\s?/gi, '') + '...', {className:'watermark', useNative:false} );
});

/* Stylish Select */
$('.input-select select').each(function(){
	var $this = $(this);
	$this.sSelect().change(function() {
		$this = $(this);
		if($this.getSetSSValue() == '') {
			$this.closest('.input-select').find('.selectedTxt').addClass('watermark');
		} else {
			$this.closest('.input-select').find('.selectedTxt').removeClass('watermark');
		}
	});
	if($this.getSetSSValue() == '') {
		$this.closest('.input-select').find('.selectedTxt').addClass('watermark');
	}
	$this.closest('.input-select').find('.newListSelected').addClass( $this.attr('class') );
});
if( $.browser.msie ) {
	var selCount = $(".input-select").size();
	$(".input-select").each(function(){
		$this = $(this);
		$this.css("z-index", selCount - $(".input-select").index(this));
	});
}
/* Simple Scroll */
//$('.form-item-select .newListSelected ul').jScrollPane();

/* Focus class */
$('.input-text input, .input-textarea textarea').focus(function(e) {
	$('.focus').removeClass('focus');
	$(this).closest('.form-item').find('.input').addClass('focus');
	$(this).closest('.form-item').find('.label').fadeIn(200);
	e.stopPropagation();
	$("body").click();
});
$('.input-text input, .input-textarea textarea').click(function(e) {
	e.stopPropagation();
});
$('.input-text input, .input-textarea textarea').blur(function(e) {
	$('.focus').removeClass('focus');
	$(this).closest('.form-item').find('.label').fadeOut(200);
});
$('.input-select .newListSelected').focus(function(e) {
	//$(this).addClass('focus');
});

/* Checkbox */
$('.input-checkbox input[type=checkbox]').checkbox({
	cls: 'jquery-checkbox',
	empty: '/~images/spacer.gif'
}).click(function(e) {
	$("body").click();
});

/* Clear Form */
$('a.btn-clearform').click(function() {
	$( $(this).attr('rel') ).submit();
});

});