var quoteLength = 310; var quotes = new Array(); var activeQuote = 0; var t; var $f_name; var $l_name; var $email_addr; var $location; var $device; var valid;
$(document).ready(function(){
	doHovers();
	if($("body")[0].className == "home") {setTimeout('doSlideAsk()', 1000);}
	else {
		if($("#sidebar:has(#quotes)")[0]) {doQuotes();}
	}
	if($("#sidebar:has(#snapshots)")[0]) {doSnapshots();}
	if($("#sidebar:has(#updates)")) {doUpdates();}
});
function doHovers() {
	preloads = new Object();
	$("img").each(function(i, el){
		if($(el).parent().get(0).tagName == "A") {
			var imageOffSrc =  el.src + "";
			if(imageOffSrc.indexOf("_off") != -1) {
				var imageOverSrc = imageOffSrc.replace(/_off/g, "_over");
				preloads['imageOff_' + i] = new Image(); preloads['imageOff_' + i].src = imageOffSrc; preloads['imageOver_' + i] = new Image(); preloads['imageOver_' + i].src = imageOverSrc;
				$(el).parent().mouseover(function(){$("img",this).attr("src", $("img",this).attr("src").replace(/_off/g, "_over"));});
				$(el).parent().mouseout(function(){$("img",this).attr("src", $("img",this).attr("src").replace(/_over/g, "_off"));});
			}
		}
	});
	$("input").each(function(i, el){
		if($(el).attr("src")) {
			var imageOffSrc =  el.src + "";
			if(imageOffSrc.indexOf("_off") != -1) {
				var imageOverSrc = imageOffSrc.replace(/_off/g, "_over");
				preloads['imageOff_' + i] = new Image(); preloads['imageOff_' + i].src = imageOffSrc; preloads['imageOver_' + i] = new Image(); preloads['imageOver_' + i].src = imageOverSrc;
				$(el).mouseover(function(){$(this).attr("src", $(this).attr("src").replace(/_off/g, "_over"));});
				$(el).mouseout(function(){$(this).attr("src", $(this).attr("src").replace(/_over/g, "_off"));});
			}
		}
	});
}
function doQuotes() {
	$("#quotes a").mouseover(function(){
		$(this).toggleClass('faded');
	});
	$("#quotes a").mouseout(function(){
		$(this).toggleClass('faded');
	});
	$("#quotes li").each(function(i, el) {quotes[i] = i*quoteLength;});
	if(activeQuote == 0) {$(".next").addClass('disabled');}
	if(activeQuote == quotes.length - 1) {$(".prev").addClass('disabled');}
	$(".prev").click(function() {
		if(this.className == "s prev disabled") {return;}
		clearTimeout(t);
		slideQuotes();
	});
	$(".next").click(function() {
		if(this.className == "s next disabled") {return;}
		clearTimeout(t);
		activeQuote = activeQuote - 2;
		slideQuotes();
	});
	setTimeout('slideQuotes()', 6000);
}
function doSnapshots() {
	$("#snapshots a").mouseover(function(){
		$(this).toggleClass('faded');
	});
	$("#snapshots a").mouseout(function(){
		$(this).toggleClass('faded');
	});
	$("#snapshots li").each(function(i, el) {quotes[i] = i*quoteLength;});
	if(activeQuote == 0) {$(".next").addClass('disabled');}
	if(activeQuote == quotes.length - 1) {$(".prev").addClass('disabled');}
	$(".prev").click(function() {
		if(this.className == "s prev disabled") {return;}
		clearTimeout(t);
		slideQuotes();
	});
	$(".next").click(function() {
		if(this.className == "s next disabled") {return;}
		clearTimeout(t);
		activeQuote = activeQuote - 2;
		slideQuotes();
	});
	setTimeout('slideQuotes()', 6000);
}
function slideQuotes() {
	$(".prev").removeClass('disabled'); $(".next").removeClass('disabled');
	++activeQuote;
	if(activeQuote == 0) {$(".next").addClass('disabled');}
	if(activeQuote == quotes.length - 1) {$(".prev").addClass('disabled');}
	if(activeQuote >= quotes.length) {activeQuote = 0; $(".next").addClass('disabled');}
	var margin = -(activeQuote * quoteLength);
	$("#clip ul").animate({'left' : margin}, 500, "easeInOutBack");
	t = setTimeout('slideQuotes()', 6000);
}
function doUpdates() {
	$("li.updProducts a").click(function(){
		if(!$("#updProducts").hasClass("visible")) {
			$("#updates div.visible").slideUp(500, function(){$("#updates div.visible").toggleClass('visible');});
			$("#updProducts").slideDown(500, function(){$("#updProducts").toggleClass('visible');});
			$("ul.tabs li.active").toggleClass('active');
			$("li.updProducts").toggleClass('active');
		}
	});
	$("li.updBlog a").click(function(){
		if(!$("#updBlog").hasClass("visible")) {
			$("#updates div.visible").slideUp(500, function(){$("#updates div.visible").toggleClass('visible');});
			$("#updBlog").slideDown(500, function(){$("#updBlog").toggleClass('visible');});
			$("ul.tabs li.active").toggleClass('active');
			$("li.updBlog").toggleClass('active');
		}
	});
	$("li.updNews a").click(function(){
		if(!$("#updNews").hasClass("visible")) {
			$("#updates div.visible").slideUp(500, function(){$("#updates div.visible").toggleClass('visible');});
			$("#updNews").slideDown(500, function(){$("#updNews").toggleClass('visible');});
			$("ul.tabs li.active").toggleClass('active');
			$("li.updNews").toggleClass('active');
		}
	});
}
function validateRegistration() {
	$("#registration_form").submit(function(){
		clearErrors();
		if($f_name.attr('value') == '') {showError($f_name, "Please enter your name"); valid = 0;}
		if($l_name.attr('value') == '') {showError($l_name, "Please enter your name"); valid = 0;}
		if($email_addr.attr('value') == '') {showError($email_addr, "Please enter your email address"); valid = 0;}
		if($email_addr.attr('value') != '') {
			var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
			if(reg.test($email_addr.attr('value')) == false) {showError($email_addr, "Please enter a valid email address"); valid = 0;}
		}
		if($location.attr('value') == 'NA') {showError($location, "Please select your location"); valid = 0;}
		if($device.attr('value') == 'NA') {showError($device, "Please select your device"); valid = 0;}
		if(valid == 1) {return true;}
		else {return false;}
	});
}
function clearErrors() {
	valid = 1;
	$f_name = $("#f_name");
	$l_name = $("#l_name");
	$email_addr = $("#email_addr");
	$location = $("#location");
	$device = $("#device");
	$("label").each(function(i, el){$(el).removeClass('error');});
	$("#registration_form small").remove();
}
function showError(obj, msg) {
	$("label").each(function(i, el){
		if($(el).attr('for') == $(obj).attr('id')) {
			var sml = document.createElement("small");
			sml.className = "error";
			var txt = document.createTextNode(msg);
			sml.appendChild(txt);
			$(el).removeClass(''); $(el).addClass('error');
			$(obj).after(sml);
		}
	});
}