$(document).ready(function() { 
	if (VT) {
		// multi-page actions
		switch (VT.id.toLowerCase()) {
			case "community-user-batches-activity" :
			case "community-user-wines-detail" :
			case "community-user-equipment-detail" : 
			case "community-user-pictures-batch-detail" : 
				$("div.commentStart a").bind("click", VT.utils.show_comment_form);
				$("form.commentForm a.cancel").bind("click", VT.utils.hide_comment_form);
				$("form.commentForm button").bind("click", VT.utils.post_comment);
				$("a[rel='noteimage']").lightBox({imageBtnClose: "/_images/_elements/lightbox-btn-close.gif", imageBtnPrev: "/_images/_elements/lightbox-btn-prev.gif", imageBtnNext: "/_images/_elements/lightbox-btn-next.gif", imageLoading: "/_images/_elements/lightbox-ico-loading.gif", imageBlank: "/_images/_elements/lightbox-blank.gif"});
				break;
		}
		
		// page-specific actions
		switch (VT.id.toLowerCase()) {
			case "home" : 
				// homepage
				$(".terms a").facebox();
				$("#frmSignup").bind(	"submit",
									 	function(objEvent) {
											if (!VT.validation.validate(	{
																	   		fields:	[	{id: "strEmail", type: VT.validation.formTypes.email, message: "", verify: "strEmailV"}, 
																					 	{id: "strPassword", type: VT.validation.formTypes.blank, message: "", verify: "strPasswordV"}], 
																			suppress: true
																		})) {
												
												$("#frmSignup div.row").removeClass("error");
												
												if (VT.validation.data.failed.length) {
													for (var numCounter = 0; numCounter < VT.validation.data.failed.length; numCounter++) {
														$("#" + VT.validation.data.failed[numCounter]).parent("div").parent("div").addClass("error");
													}
												}
												
												$("#frmSignup div.globalError").html("Some errors were found.  Please correct the highlighted fields.");
												if ($("#frmSignup div.globalError").css("display") == "none") {
													$("#frmSignup div.globalError").show("slow");
												}
												return false;
											} else {
												// check terms
												if (!VT.validation.validate({fields: [{id: "chkTermsAgree", type: VT.validation.formTypes.checkbox, message: ""}], suppress: true})) {
													$("#frmSignup div.globalError").html("You must agree to the Terms and Conditions of the site.");
													if ($("#frmSignup div.globalError").css("display") == "none") {
														$("#frmSignup div.globalError").show("slow");
													}
													return false;
												} else {
													return true;
												}
											}
										});
				break;
				
			case "contact" : 
				$("#frmContact").bind(	"submit",
									 	function(objEvent) {
											if (!VT.validation.validate(	{
																	   		fields:	[	{id: "strName", type: VT.validation.formTypes.blank, message: ""}, 
																						{id: "strPhone", type: VT.validation.formTypes.blank, message: ""}, 
																						{id: "strEmail", type: VT.validation.formTypes.email, message: ""}, 
																						{id: "intSubject", type: VT.validation.formTypes.selectbox, message: ""}, 
																					 	{id: "txtMessage", type: VT.validation.formTypes.text, message: ""}], 
																			suppress: true, 
																			callback: VT.forms.post_process, 
																			form: "frmContact"
																		})) {
												
												$("#frmContact div.row").removeClass("error");
												
												if (VT.validation.data.failed.length) {
													for (var numCounter = 0; numCounter < VT.validation.data.failed.length; numCounter++) {
														$("#" + VT.validation.data.failed[numCounter]).parent("div").parent("div").addClass("error");
													}
												}
												return false;
											} else {
												return true;
											}
										});
				break;

			case "community-user-activity" : 
				var arrData				= new Array();
				var objLabelElements	= $("#total-volume-graph dl>dt");
				var objDataElements		= $("#total-volume-graph dl>dd");
				
				if ((objLabelElements.length) && (objDataElements.length) && (objLabelElements.length == objDataElements.length)) {
					for (var intCounter = 0; intCounter < objLabelElements.length; intCounter++) {
						arrData.push([$(objLabelElements[intCounter]).html(), parseFloat($(objDataElements[intCounter]).text())]);
					}
				}
				
				if (arrData.length) {
					VT.graphs.activity = new Highcharts.Chart({
						credits: {
							enabled: false
						},
						chart: {
							spacingTop: 0, 
							renderTo: "total-volume-graph", 
							plotBackgroundColor: null, 
							plotBorderWidth: null, 
							plotShadow: false
						}, 
						title: {
							text: ""
						}, 
						legend: {
							borderWidth: 0, 
							y: -50, 
							itemStyle: {
								color: "#333333", 
								fontWeight: "normal", 
								fontFamily: "sans-serif", 
								fontSize: "14px", 
								lineHeight: "14px", 
								letterSpacing: "-1px"
							}
						}, 
						tooltip: {
							style: {
								color: "#333333", 
								fontFamily: "sans-serif", 
								fontSize: "14px", 
								lineHeight: "14px", 
								letterSpacing: "-1px"
							}, 
							formatter: function() {
								return "<strong>" + this.y + "%</strong>";
							}
						}, 
						plotOptions: {
							pie: {
								allowPointSelect: true, 
								cursor: "pointer", 
								dataLabels: {
									enabled: false
								}, 
								showInLegend: true
							}
						}, 
						series: [{
							type: "pie", 
							name: "Volume", 
							data: arrData
						}]
					});
				}
				break;
				
			case "community-user-wines-detail" :
				$("#wine-photos table>tbody>tr>td>a")
					.bind(	"click", 
							function() {
								$("#wine-photos>img:first-of-type")
									.attr("src", $(this).attr("rel")); 
							});
				break;
		}
	}
});
