var $j = jQuery.noConflict(); // # Assigns jquery calls to $j
$j(document).ready(function() {
	// # Check form for required fields
	$j('input.required, select.required, textarea.required').siblings('label').addClass('required');
	$j('input._text[name$="phone"]').mask("(999) 999-9999",{placeholder:" "});
	$j('form').each(function(i){
		$j(this).validate();
	});
	
	// # --  General Jquery Helpers
	// # Submit form onchange for select
	$j('select._onchange').change(function(e){
		$j(this).parents('form').submit();
	});

	// # <a> tag is submit button within form
	$j('a._submit').click(function(e){
		e.preventDefault();
		$j(this).parents('form').submit();
	});
	
	// # Default input
	$j('input._default').click(function(e){
		var rel = $j(this).attr('rel');
		var val = $j(this).val();
		if (val == rel) {			
			$j(this).val('');
		}
	});	
	$j('input._default').focusout(function(e){
		var rel = $j(this).attr('rel');
		var val = $j(this).val();
		if (val == '') {
			$j(this).val(rel);
		}
	}).focusout();
	
	// # Auto Toggle
	$j('a._toggle').click(function(e){
		e.preventDefault();
		var href = $j(this).attr('href');
		text = $j(this).text();
		if (text.match('More') != null) {
			text = text.replace(/More/,'Less');
		}
		else if (text.match('Less') != null) {
			text = text.replace(/Less/,'More');
		}
		$j(this).text(text);
		$j(this).toggleClass('_toggled');
		$j(href).slideToggle(100);
	});
	
	// # Autofloat images in text boxes
	$j('._text img, ._featurebox img').each(function(i){
		style = $j(this).attr('style');
		if (style != null) {
			if (style.match(/float:\s?left/i) != null) {
				$j(this).addClass('_imgLeft');
			}
			else if (style.match(/float:\s?right/i) != null) {
				$j(this).addClass('_imgRight');
			}
		}
	});	
	
	// # Init Prefab Scripts
	$j("a[rel*=lightbox]").prettyPhoto();
	
	// # IE Fixes
	if ($j.browser.msie != null) {	
		$j('img[src*=".png"]').addClass('unitPng');		
		$j('#nav>li:last-child').addClass('_last-child');
		$j('fieldset:last-child').addClass('_last-child'); 
		$j('p:last-child').addClass('_last-child');
	}
});
