$(document).ready(function() {
	$(document).cheatCode({
		activated : function(){
			alert('Cheat Code Activated!');
		}
	});
	
	$("a.fbicon").click(function () {
		$("div#facebook").fadeIn();
		return false;
	});
	
	$("div#fbclose a").click(function () {
		$("div#facebook").fadeOut();
		return false;
	});
	
	$("#randomPost").load("/random/",  {test: 3244324});
	$("#another").click(function(){
	   $("#randomPost")
	            .text("Loading...")
	            .load("/random/", {test: 3244324});
	
			//var text = $("div#randomPost small a").html();
			////$("div#randomPost small a").attr("href", all)
			//alert(text);
	   return false;
	});
	
	$("div#randomPost li div.return a").live("click", function(){
		return false;
		
	});
	
		
	
	
	
	
	
	
	
	
	
	
var tourTest = $("div#content").attr("class");
if (tourTest === "tour"){
	
	
	
	$.get('/wp-content/themes/tucker_movie/js/GPSxml.xml', function(xml) {
		
							var tinyIcon = new GIcon();
							tinyIcon.image = "/wp-content/themes/tucker_movie/images/markers/image.png";
							tinyIcon.printImage = '/wp-content/themes/tucker_movie/images/markers/printImage.gif';
							tinyIcon.mozPrintImage = '/wp-content/themes/tucker_movie/images/markers/mozPrintImage.gif';
							tinyIcon.iconSize = new GSize(28,48);
							//tinyIcon.shadow = '/wp-content/themes/tucker_movie/images/markers/shadow.png';
							tinyIcon.transparent = '/wp-content/themes/tucker_movie/images/markers/transparent.png';
							//tinyIcon.shadowSize = new GSize(52,48);
							tinyIcon.printShadow = '/wp-content/themes/tucker_movie/images/markers/printShadow.gif';
							tinyIcon.iconAnchor = new GPoint(14,48);
							tinyIcon.infoWindowAnchor = new GPoint(14,0);
							
							markerOptions = { icon:tinyIcon };
		
		
	           $(xml).find('entry').each(function() {
								
								var lat = $(this).find('lat').text();
								var lng = $(this).find('lng').text();
								var city = $(this).find('city').text();
								var state = $(this).find('state').text();
								var venue = $(this).find('venue').text();
								var date = $(this).find('date').text();
								
								var all = "<strong>"+date+"</strong><br /><br />"+city+", "+state+"<br />"+venue;
													
								
								
								var point = new GLatLng(lat,lng);
					      var marker = new GMarker(point, markerOptions);
								map.addOverlay(marker);
								var mapControl = new GMapTypeControl();
								map.addControl(mapControl);
								map.addControl(new GLargeMapControl());
								GEvent.addListener(marker, "click", function() {
									marker.openInfoWindowHtml("<div style='color:#000; font-size: 12px;'>"+all+"</div>");
								});
								
	           })
	       });
	
	//alert("tour page");
	// Google Maps Integration

	

	    if (GBrowserIsCompatible()) { 

	      // A function to create the marker and set up the event window
	      // Dont try to unroll this function. It has to be here for the function closure
	      // Each instance of the function preserves the contends of a different instance
	      // of the "marker" and "html" variables which will be needed later when the event triggers.    
	      function createMarker(point,html) {
	        var marker = new GMarker(point);
	        GEvent.addListener(marker, "click", function() {
	          marker.openInfoWindowHtml(html);
	        });
	        return marker;
	      }

	      // Display the map, with some controls and set the initial location 
	      var map = new GMap2(document.getElementById("map"));
	      map.addControl(new GLargeMapControl());
	      map.addControl(new GMapTypeControl());
	      map.setCenter(new GLatLng(37.09024,-95.712891), 4);

	      // Set up three markers with info windows 

	      //var point = new GLatLng(43.65654,-79.90138);
	      //var marker = createMarker(point, "test")
	      //map.addOverlay(marker);
	
				
        //
	      //var point = new GLatLng(43.91892,-78.89231);
	      //var marker = createMarker(point,'Some stuff to display in the<br>Second Info Window')
	      //map.addOverlay(marker);
        //
	      //var point = new GLatLng(43.82589,-79.10040);
	      //var marker = createMarker(point,'Some stuff to display in the<br>Third Info Window')
	      //map.addOverlay(marker);

	    }

	    // display a warning if the browser was not compatible
	    else {
	      alert("Sorry, the Google Maps API is not compatible with this browser");
	    }



}	
	
	
	
	// Contact Form
	$("form#contactform #submit").click(function(){					   				   
			$(".error").hide();
			//$(this).attr("disabled", false);
			var hasError = false;
			var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;

			var senderName = $("#name").val();

			var emailFromVal = $("#emailFrom").val();
			if(emailFromVal == '') {
				$("#emailFrom").after('<div class="error">You forgot to enter the email address to send from.</div>');
				hasError = true;
			} else if(!emailReg.test(emailFromVal)) {	
				$("#emailFrom").after('<div class="error">Enter a valid email address to send from.</div>');
				hasError = true;
			}

			var phoneVal = $("#phone").val();
			//if(subjectVal == '') {
			//	$("#subject").after('<div class="error">You forgot to enter the subject.</div>');
			//	hasError = true;
			//}

			var messageVal = $("#message").val();
			if(messageVal == '') {
				$("#message").after('<div class="error">You forgot to enter the message.</div>');
				hasError = true;
			}
			
			var humanVal = $("#human").val();
			if(humanVal != 'beerinhell') {
				$("#human").after('<div class="error">We don\'t take kindly to robots.</div>');
				hasError = true;
			}


			if(hasError == false) {
				//$(this).attr("disabled", true);
				$("#sendEmail li.buttons").append('<img src="/wp-content/themes/tucker_movie/images/ajax-loader.gif" alt="Loading" id="loading" />');

				$.post("/wp-content/themes/tucker_movie/scripts/sendMail.php",
	   				{ emailTo: "tuckermax@gmail.com", name: senderName,  emailFrom: emailFromVal, subject: phoneVal, message: messageVal },
	   					function(data){
							$("#sendEmail").slideUp("slow", function() {				   

								$("#sendEmail").before('<h3>Sent!</h3><p>Your email was sent</p>');											
							});
	   					}
					 );
			}

			return false;
		});
	
	$('input#zip').click(function(){
		$(this).val("");
	});
	
		$("form#zipform #submit").click(function(){					   				   
				$(".error").hide();
				//$(this).attr("disabled", false);
				var hasError = false;

				var zipVal = $("#zip").val();
				if(zipVal == 'City, State') {
					$("#response").html('<div class="error">You forgot to enter a Zip Code</div>');
					hasError = true;
				}
				
			if(hasError == false) {
					//$(this).attr("disabled", true);
					//$("#sendEmail li.buttons").append('<img src="/wp-content/themes/tucker_movie/images/ajax-loader.gif" alt="Loading" id="loading" />');

					$.post("/wp-content/themes/tucker_movie/scripts/sendZip.php",
		   				{ emailTo: "ihtsbihtheater@gmail.com", zip: zipVal },
		   					function(data){
								$("#zipform").slideUp("slow", function() {				   

									$("#response").html('<p>Thanks,we\'ve logged your request!</p>');											
								});
		   					}
						 );
				}

				return false;
			});
	
	
	
	
	
	
	
	//End Doc Ready
});