Shadowbox.loadSkin('classic', '/includes/js/shadowbox/skin');				// use the "classic" skin
Shadowbox.loadLanguage('en', '/includes/js/shadowbox/lang');					// use the English language
Shadowbox.loadPlayer(['img', 'flv', 'iframe', 'html'], '/includes/js/shadowbox/player');	// use img and qt players

$(document).ready(function(){
	if ($("#accordion").length > 0 ) {
		$("#accordion").accordion({header: "a.header", autoHeight: true});		// Sidebar accordion
	}
	$('a[@href^="http://"]').attr('target', '_blank');						// External links
	$('a[@href^="http://www.easywater.com"]').attr('target', '_self');						// External links
	clearinputs();															// Clear inputs on click
	current();																// Current page
	quoteChange(9000);														// Quotes
	required();																// Required form fields
	Shadowbox.init();														// Start Shadowbox
	stripeTables();															// Stripe the tables
})

function required() {
	$('form').submit(function() {
		go = true;
		$('.required', this).css('background', 'transparent').each(function() {
			if($(this).attr('value') == "" || $(this).attr('value') == $(this).attr('rel') || $(this).attr('value') == "unselected") {
				$(this).css('background', '#FAA').css('color', '#222');
				$(this).change(function() {
					$(this).css('background', 'transparent');
				});
				go = false;
			}
		});
		return go;
	});
}

function current() {
	var file_name = document.location.href;
	var end = (file_name.indexOf("?") == -1) ? file_name.length : file_name.indexOf("?");
	var filename = file_name.substring(file_name.lastIndexOf("/")+1, end);
	$('ul.menu li a').each(function() {
		if($(this).attr('href') == filename) {
			$(this).addClass('current');
		}
	});
}

function clearinputs() {
	$("input.clearvalue").addClass('normal').click(function() {
		if($(this).hasClass('normal')) {
			$(this).attr('value', '').css('color', '#222').removeClass('normal');
		}
	});
	$("textarea.clearvalue").addClass('normal').click(function() {
		if($(this).hasClass('normal')) {
			$(this).attr('value', '').text('').css('color', '#222').removeClass('normal');
		}
	});
}

/* -- Scrolling Quotes -- */
var quotes = new Array(
	new Array("I am extremely happy with this treated water. For the true solution to my hard water problem, I say thank you Freije!", " - Barry S., North Las Vegas, NV"),
	new Array("Thanks to my EasyWater, I'm saving my back because I no longer have to carry those heavy bags down to the basement!", " - Garth C., Carmel, Indiana"),
	new Array("I was amazed how easy our tub was to clean after installing our EasyWater. I no longer have to scrub the tub for scum.", " - Annalise C., Indianapolis, IN"),
	new Array("My humidifier was always covered with scale, and after a week, EasyWater completely cleared it out. It works great.", " - George A., Newcastle, NE"),
	new Array("It's a good tool in our bag to carry out to our customers... it's a great device to prevent scale in your water heater and pipes.", " - Jeff K., (Plumber) IN"),
	new Array("My wife has commented that she now uses &frac14; of laundry detergent and &frac12; the amount of shampoo.", " - Bob B., Spokane, WA")
	);
num = Math.floor(Math.random()*(quotes.length + 1));

function quoteChange(speed) {
	$("#quotes").find("p").fadeOut(300, function(){
			$(this).html(quotes[num][0] +"<span>"+ quotes[num][1] +"</span>").fadeIn(300);
		});
	if(num + 1 >= quotes.length)
		num = 0;
	else
		num++;
	setTimeout('quoteChange('+speed +')', speed);
}

function stripeTables() {
   $(".stripeMe tr").mouseover(function(){$(this).addClass("over");})
					.mouseout(function(){$(this).removeClass("over");});
   $(".stripeMe tr:odd").addClass("alt");
}