function wndw(windowCSSQuery) {
	this.sWindow = windowCSSQuery;

	this.init = function() {
		// bind close button
		var oThis = this;							// jQuery object causes change of reference 'this'
		$(this.sWindow).find(".btns .close").click(function() {
			oThis.closeWindow();
			return false;
		});
		return;
	}
	this.openWindow = function() {
		// make sure window can fit on screen
		if ($(window).height() > $(this.sWindow).height()) {
			$(this.sWindow).css({position:"fixed"});
		} else {
			$(this.sWindow).css({position:"absolute"});
		}
		$(this.sWindow).find(".error").remove();	// clear any old error messages
		var oThis = this;							// jQuery object causes change of reference 'this'
		$("#blackout").fadeIn(150,function() {
			$(oThis.sWindow).fadeIn(150);
		});

		return;
	};
	this.closeWindow = function() {
		$(this.sWindow).fadeOut(150,function() {
			$("#blackout").fadeOut(150);
			return;
		});
		return;
	};
	
	this.init();
}

$(document).ready(function() {
	$("#nav-main > li").hover(
		function() {
//			$(this).find("a").addClass("over");
			// show sub-menu
			$(this).find("ul").show();
			return;
		},
		function() {
//			$(this).find("a").removeClass("over");
			// hide submenu
			$(this).find("ul").hide();
			return;
		}
	);
	
	// create window objects
	var wndws = new Array();
	$(".window").each(function() {
		if ($(this).attr("id")) {
			wndws[$(this).attr("id")] = new wndw("#"+$(this).attr("id"));
		}
		return;
	});
	
	$(".btn-get-free-report").click(function() {
		wndws["window-get-free-report"].openWindow();
		return false;
	});
	
	$(".link-get-quote").click(function() {		
		wndws["window-get-quote"].openWindow();
		return false;
	});
	
	$(".btn-get-quote").click(function() {		
		wndws["window-get-quote"].openWindow();
		return false;
/*		
		pageTracker._trackPageview('/web-design-hamilton-ontario/form/');
*/
	});
	
	$("[name='frmQuote']").submit(function() {
		$.post(
			"/_includes/ajax/form-request.php",
			{
				mode:"quote",
				fname:$("#window-get-quote input[name='txtFName']").val(),
				lname:$("#window-get-quote input[name='txtLName']").val(),
				email:$("#window-get-quote input[name='txtEMail']").val(),
				subject:$("#window-get-quote select[name='selSubject'] :selected").text(),
				phone:$("#window-get-quote input[name='txtPhone']").val(),
				desc:$("#window-get-quote textarea[name='txaDesc']").val()
			},
			function(xml) {
				$(xml).find("result").each(function() {
					if ($(this).attr("type") == "success") {
						// output/redirect with 'thank you'
						$("#window-get-quote .body").html("");
						html = "<div class=\"thankyou\">\n"+
							"\t<h2>Thank You</h2>\n"+
							"\t<p>Thank you for contacting Carbonated.</p>\n"+
							"</div>\n";
					
/*
						html += "<script language='javascript'>$(document).ready(function (){pageTracker._trackPageview('/web-design-hamilton-ontario/complete/'); gwoTracker._trackPageview('/2117019019/goal');});</script>\r\n";
*/
					
						$("#window-get-quote .body").html(html);
					} else {
						// clear all error messages
						$(".error").remove();
						$(this).find("error").each(function() {
							// output error messages
							$("#window-get-quote [name='"+$(this).attr("el")+"']").after("<div class=\"error\">"+$(this).text()+"</div>\n");
						});
					}
				});
			}
		);
		return false;
	});

	$("#frmQuote input").focus(function() {
		$(this).parents(".el").addClass("focus");
	});
	$("#frmQuote select").focus(function() {
		$(this).parents(".el").addClass("focus");
	});
	$("#frmQuote textarea").focus(function() {
		$(this).parents(".el").addClass("focus");
	});
	$("#frmQuote input").blur(function() {
		$(this).parents(".el").removeClass("focus");
	});
	$("#frmQuote textarea").blur(function() {
		$(this).parents(".el").removeClass("focus");
	});
	$("#frmQuote select").blur(function() {
		$(this).parents(".el").removeClass("focus");
	});
	
	$("[name='frmReport']").submit(function() {
		$.post(
			"/_includes/ajax/form-request.php",
			{
				mode:"report",
				fname:$("#window-get-free-report input[name='txtFName']").val(),
				lname:$("#window-get-free-report input[name='txtLName']").val(),
				email:$("#window-get-free-report input[name='txtEMail']").val(),
				phone:$("#window-get-free-report input[name='txtPhone']").val(),
				website:$("#window-get-free-report input[name='txtURL']").val()
			},
			function(xml) {
				$(xml).find("result").each(function() {
					if ($(this).attr("type") == "success") {
						// output/redirect with 'thank you'
						$("#window-get-free-report .body").html("");
						html = "<div class=\"thankyou\">\n"+
							"\t<h2>Thank You</h2>\n"+
							"\t<p>Thank you for contacting Carbonated.</p>\n"+
							"</div>\n";
					
/*
						html += "<script language='javascript'>$(document).ready(function (){pageTracker._trackPageview('/web-design-hamilton-ontario/complete/'); gwoTracker._trackPageview('/2117019019/goal');});</script>\r\n";
*/
					
						$("#window-get-free-report .body").html(html);
					} else {
						// clear all error messages
						$(".error").remove();
						$(this).find("error").each(function() {
							// output error messages
							$("#window-get-free-report [name='"+$(this).attr("el")+"']").after("<div class=\"error\">"+$(this).text()+"</div>\n");
						});
					}
				});
			}
		);
		return false;
	});
	
	$("#frmReport input").focus(function() {
		$(this).parents(".el").addClass("focus");
	});
	$("#frmReport select").focus(function() {
		$(this).parents(".el").addClass("focus");
	});
	$("#frmReport textarea").focus(function() {
		$(this).parents(".el").addClass("focus");
	});
	$("#frmReport input").blur(function() {
		$(this).parents(".el").removeClass("focus");
	});
	$("#frmReport textarea").blur(function() {
		$(this).parents(".el").removeClass("focus");
	});
	$("#frmReport select").blur(function() {
		$(this).parents(".el").removeClass("focus");
	});

});