function infoOpen() {
	$( "#flavorFlowChart" ).dialog('close');
	$( "#infoReqDialog" ).dialog('open');
	alert("open");
	
}
$.extend({
  getUrlVars: function(){
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
      hash = hashes[i].split('=');
      vars.push(hash[0]);
      vars[hash[0]] = hash[1];
    }
    return vars;
  },
  getUrlVar: function(name){
    return $.getUrlVars()[name];
  }
});


$(document).ready(function(){
	
	
	
			//init. slideshowController 
			$('#slideshow').cycle({
				fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
			});
			
	jQuery(
		function($){
			
			
			
		//	jQuery.extend(pageElement, SlideshowController);
		//	SlideshowController.start();
			
		//code taken/adapted from this here: http://jqueryui.com/demos/dialog/#modal-form
		function updateTips( t ) {
			tips
				.text( t )
				.addClass( "ui-state-highlight" );
			setTimeout(function() {
				tips.removeClass( "ui-state-highlight", 1500 );
			}, 500 );
		}

		function checkLength( o, n, min, max ) {
			if ( o.val().length > max || o.val().length < min ) {
				o.addClass( "ui-state-error" );
				updateTips( "Length of " + n + " must be between " +
					min + " and " + max + "." );
				return false;
			} else {
				return true;
			}
		}

		function checkRegexp( o, regexp, n ) {
			if ( !( regexp.test( o.val() ) ) ) {
				o.addClass( "ui-state-error" );
				updateTips( n );
				return false;
			} else {
				return true;
			}
		}
						
		$( "#eventDialog" ).dialog({
			autoOpen: false,
			resizable: false,
			height: 450,
			width: 600,
			modal: true,
			buttons: {
				"Submit": function() {
					var name = $( "#name3" ),
					email = $( "#email3" ),
					addressOne = $("#address31"),
					addressTwo = $("#address32"),
					city = $("#city3"),
					state = $("#state3"),
					phone = $("#phone3"),
					//password = $( "#password" ),
					allFields = $( [] ).add( name ).add( addressOne ).add( addressTwo ).add( city ).add( state ).add( phone ).add( email ),
					tips = $( ".validateTips" );
					var bValid = true;
					allFields.removeClass( "ui-state-error" );

					/*bValid = bValid && checkLength( name, "username", 3, 16 );
					bValid = bValid && checkLength( email, "email", 6, 80 );
					bValid = bValid && checkLength( password, "password", 5, 16 );*/

					//bValid = bValid && checkRegexp( name, /^[a-z]([0-9a-z_])+$/i, "Username may consist of a-z, 0-9, underscores, begin with a letter." );
					// From jquery.validate.js (by joern), contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
					bValid = bValid && checkRegexp( email, /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i, "eg. youremail@yourdomain.com" );
					//bValid = bValid && checkRegexp( password, /^([0-9a-zA-Z])+$/, "Password field only allow : a-z 0-9" );

					if ( bValid ) {
						$( "#users tbody" ).append( "<tr>" +
		//					"<td>" + name.val() + "</td>" + 
							"<td>" + email.val() + "</td>" + 
						"</tr>" ); 
						//alert($("#infoReqForm"));
						$("#eventReq").submit();
						//$(this).infoReqForm.submit();
						$( this ).dialog( "close" );
						//window.location = "http://www.parkerproducts.com/rebuild/include/mailer.php?name="+name.val()+"&addressOne="+addressOne.val()+"&addressTwo="+addressTwo.val()+"&city="+city.val()+"&state="+state.val()+"&phone="+phone.val()+"&email="+email.val();
					}
				},
				Cancel: function() {
					$( this ).dialog( "close" );
				}
			},
			close: function() {
				allFields.val( "" ).removeClass( "ui-state-error" );
			},
		});


			$("#infoReq").click(function() {
				$("#infoReqDialog").dialog("open" );
				tips = $(".validateTips");
			});
		
			
			$( "#featureFlavor" )
			.click(function() {
				$( "#meetingReqDialog" ).dialog( "open" );
				tips = $( ".validateTips" );
			});
			
			$( "#flavor").parent().removeAttr("href");
			
			$( "#flavor" )
			.click(function(){
				$("#flavorFlowChart").dialog("open");
				$("#flavorFlowChart").parent().removeClass("ui-widget-content");
			});
			
			$( "#flavorFlowChart").dialog({
				autoOpen:false,
				resizable:false,
				height:630,
				width:800,
				modal:true
			});
			
			$( "#meetingReqDialog" ).dialog({
			autoOpen: false,
			resizable: false,
			height: 450,
			width: 314,
			modal: true,
			buttons: {
				"Submit": function() {
					var name = $( "#name2" ),
					email = $( "#email2" ),
					addressOne = $("#address21"),
					addressTwo = $("#address22"),
					city = $("#city2"),
					state = $("#state2"),
					phone = $("#phone2"),
					//password = $( "#password" ),
					allFields = $( [] ).add( name ).add( addressOne ).add( addressTwo ).add( city ).add( state ).add( phone ).add( email ),
					tips = $( ".validateTips" );
					
					var bValid = true;
					allFields.removeClass( "ui-state-error" );

					/*bValid = bValid && checkLength( name, "username", 3, 16 );
					bValid = bValid && checkLength( email, "email", 6, 80 );
					bValid = bValid && checkLength( password, "password", 5, 16 );*/

					//bValid = bValid && checkRegexp( name, /^[a-z]([0-9a-z_])+$/i, "Username may consist of a-z, 0-9, underscores, begin with a letter." );
					// From jquery.validate.js (by joern), contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
					bValid = bValid && checkRegexp( email, /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i, "eg. youremail@yourdomain.com" );
					//bValid = bValid && checkRegexp( password, /^([0-9a-zA-Z])+$/, "Password field only allow : a-z 0-9" );

					if ( bValid ) {
						$( "#users tbody" ).append( "<tr>" +
							//"<td>" + name.val() + "</td>" + 
							"<td>" + email.val() + "</td>" + 
						"</tr>" ); 
						//alert($("#infoReqForm"));
						$("#meetingReqForm").submit();
						//$(this).infoReqForm.submit();
						$( this ).dialog( "close" );
						//window.location = "http://www.parkerproducts.com/rebuild/include/mailer.php?name="+name.val()+"&addressOne="+addressOne.val()+"&addressTwo="+addressTwo.val()+"&city="+city.val()+"&state="+state.val()+"&phone="+phone.val()+"&email="+email.val();
					}
				},
				Cancel: function() {
					$( this ).dialog( "close" );
				}
			},
			close: function() {
				allFields.val( "" ).removeClass( "ui-state-error" );
			}
		});
		
		$( "#infoReqDialog" ).dialog({
			autoOpen: false,
			resizable: false,
			height: 450,
			width: 600,
			modal: true,
			buttons: {
				"Submit": function() {
					var name = $( "#name1" ),
					email = $( "#email1" ),
					addressOne = $("#address11"),
					addressTwo = $("#address12"),
					city = $("#city1"),
					state = $("#state1"),
					phone = $("#phone1"),
					//password = $( "#password" ),
					allFields = $( [] ).add( name ).add( addressOne ).add( addressTwo ).add( city ).add( state ).add( phone ).add( email ),
					tips = $( ".validateTips" );
					var bValid = true;
					allFields.removeClass( "ui-state-error" );

					/*bValid = bValid && checkLength( name, "username", 3, 16 );
					bValid = bValid && checkLength( email, "email", 6, 80 );
					bValid = bValid && checkLength( password, "password", 5, 16 );*/

					//bValid = bValid && checkRegexp( name, /^[a-z]([0-9a-z_])+$/i, "Username may consist of a-z, 0-9, underscores, begin with a letter." );
					// From jquery.validate.js (by joern), contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
					bValid = bValid && checkRegexp( email, /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i, "eg. youremail@yourdomain.com" );
					//bValid = bValid && checkRegexp( password, /^([0-9a-zA-Z])+$/, "Password field only allow : a-z 0-9" );

					if ( bValid ) {
						$( "#users tbody" ).append( "<tr>" +
							//"<td>" + name.val() + "</td>" + 
							"<td>" + email.val() + "</td>" + 
						"</tr>" ); 
						//alert($("#infoReqForm"));
						$("#infoReqForm").submit();
						//$(this).infoReqForm.submit();
						$( this ).dialog( "close" );
						//window.location = "http://www.parkerproducts.com/rebuild/include/mailer.php?name="+name.val()+"&addressOne="+addressOne.val()+"&addressTwo="+addressTwo.val()+"&city="+city.val()+"&state="+state.val()+"&phone="+phone.val()+"&email="+email.val();
					}
				},
				Cancel: function() {
					$( this ).dialog( "close" );
				}
			},
			close: function() {
				allFields.val( "" ).removeClass( "ui-state-error" );
			}
		});
			
			//events
			for(var i = 1;i<20;i++){
			$( "#ev" + i )
				.click(function() {
					//alert($("#eventGrab").attr("value",$(this).attr("data-date")));
					$("#evtTitleF").text($(this).find(".evtTitle").text());
				//	alert($(this).find(".location").text());
					$("#evtDateF").text($(this).attr("data-date"));
					$("#evtAddyF").text($(this).attr("data-address"));
					$("#evtBoothF").text($(this).find(".location").text());
					$("#evtWebsiteF").text($(this).attr("data-website"));
					$("#evtWebsiteF").attr("href",$(this).attr("data-website"));
					$("#evtDescF").text($(this).attr("data-desc"));
					//("#eventDialog".attr("value"
					$("#eventGrab").attr("value",$(this).attr("data-date"));
					$("#eventDialog").attr("value",$(this).attr("data-date"));
					$("#eventDialog").dialog("option","title",$(this).attr("data-date"));
					$( "#eventDialog" ).dialog( "open" );
					tips = $( ".validateTips" );
				});			
			}
		}
	);
	var contactTrue = $.getUrlVar('contact');
	if(contactTrue) {
	$( "#infoReqDialog" ).dialog('open');
	}
	$('#info-btn').click(function(){ infoOpen() });
});

