
// jQuery Fade-In & Fade-Out Fix for IE7
jQuery.fn.fadeInFix = function(speed, easing, callback) {
	return this.animate({opacity: 'show'}, speed, easing, function() {
		if (jQuery.browser.msie)
			this.style.removeAttribute('filter');
		if (jQuery.isFunction(callback))
			callback();
	});
};
jQuery.fn.fadeOutFix = function(speed, easing, callback) {
	return this.animate({opacity: 'hide'}, speed, easing, function() {
		if (jQuery.browser.msie)
			this.style.removeAttribute('filter');
		if (jQuery.isFunction(callback))
			callback();
	});
};


// jQuery Form Placeholders
(function($) {
	$.placeholder = { className: '_placeholder', supportedNatively: function(element) {
		var testInput = document.createElement(element);
		return 'placeholder' in testInput;
	}, backwardsCompatibility: function() {	
		if (!$.placeholder.supportedNatively('input') && !$.placeholder.supportedNatively('textarea')) { var elementSelector = ':input'; }
		else if (!$.placeholder.supportedNatively('textarea')) { var elementSelector = 'textarea'; }
		else { var elementSelector = null; }
		if (elementSelector) {
			$(window).unload(function() {
				$(elementSelector + '.' + $.placeholder.className).val('');
			});   
			$(elementSelector + '[placeholder]').each(function() {
				var $this = $(this);
				var placeholder = $this.attr('placeholder');
				if (!$this.attr('defaultValue') && $this.val() == placeholder) {
					$this.val('');
				}     
			$this.blur(function() {
				if (this != document.activeElement && $this.val() == '') { $this.addClass($.placeholder.className).val(placeholder); }
			}).focus(function() {
				if ($this.hasClass($.placeholder.className)) { $this.val('').removeClass($.placeholder.className); }
			}).change(function() {
				if ($this.hasClass($.placeholder.className)) { $this.removeClass($.placeholder.className); }
			}).parents('form:first').submit(function() { $this.triggerHandler('focus'); }).end().triggerHandler('blur');
			});
		}}
	};
	$($.placeholder.backwardsCompatibility);
})(jQuery);


// jQuery Custom Checkboxes & Radio Buttons
jQuery.fn.customInput = function(){
	$(this).each(function(i){
		if($(this).is('[type=checkbox],[type=radio]')){
			var input = $(this);
			var partConfig = input.parents('div.builder').parent('div').attr('id');
			var label = $('label[for='+input.attr('id')+']');
			var inputType = (input.is('[type=checkbox]')) ? 'checkbox' : 'radio';
			$('<div class="custom-'+ inputType +'"></div>').insertBefore(input).append(input, label);
			var allInputs = $('input[name='+input.attr('name')+']');
			var label = $('label[for='+input.attr('id')+']');
			label.hover(
				function(){
					$(this).addClass('hover');
					if(inputType == 'checkbox' && input.is(':checked')){ $(this).addClass('checkedHover'); }
				},
				function(){ $(this).removeClass('hover checkedHover'); }
			);
			input.bind('updateState',function(){
				if(input.is(':checked')){
					if(input.is(':radio')){
						allInputs.each(function(){ $('label[for='+$(this).attr('id')+']').removeClass('checked'); });
					};
					label.addClass('checked');
				} else { label.removeClass('checked checkedHover checkedFocus'); }
			})
			.trigger('updateState')
			.click(function(){ $(this).trigger('updateState'); })
			.focus(function(){
				label.addClass('focus');
				if(inputType == 'checkbox' && input.is(':checked')){ $(this).addClass('checkedFocus'); }
			})
			.blur(function(){ label.removeClass('focus checkedFocus'); });
		}
	});
};


// Javascript Odd-Even Table Rows
var stripe = function() {
	var tables = document.getElementsByTagName('table');
	for(var x=0;x!=tables.length;x++){
		var table = tables[x];
		if (! table) { return; }
		var tbodies = table.getElementsByTagName('tbody');
		for (var h = 0; h < tbodies.length; h++) {
			var even = true;
			var trs = tbodies[h].getElementsByTagName('tr');
			
			// Last Row
			var z = trs.length - 1;
			trs[z].className += ' last';
			
			for (var i = 0; i < trs.length; i++) {
				trs[i].onmouseover=function(){
					this.className += ' ruled'; return false
				}
				trs[i].onmouseout=function(){
					this.className = this.className.replace('ruled', ''); return false
				}
				if(even)
				trs[i].className += ' even';
				even = !even;
			}
		}
	}
}
if (window.attachEvent) {window.attachEvent('onload', stripe);}
else if (window.addEventListener) {window.addEventListener('load', stripe, false);}
else {document.addEventListener('load', stripe, false);}