$(document).ready(function(){

	$('#dialog').jqm();


	$('.ajaxnewslink').click(function(event){
		var newshref = $(this).attr('href');
		event.preventDefault();
		$('#body-copy.press').animate({'opacity':0},400,function(){
			$(this).load(newshref,function(){
				$(this).animate({'opacity':1},400)
			})
		});
	});

	$('#archive h3').css('cursor','pointer').click(function(){
		if($(this).next('ul').css('display') == 'none'){
			$(this).next('ul').show();
			$(this).children('.windowshade').addClass('open');
		}else{
			$(this).next('ul').hide();
			$(this).children('.windowshade').removeClass('open');
		}
	}).next('ul').hide().end().children('.windowshade').removeClass('open')
	
	$('#archive h3:eq(0)').children('.windowshade').addClass('open').end().next('ul').show();

 
    //Set opacity on each span to 0%
    $(".rollover").css({'opacity':'0'});
 
	$('.img_list a').hover(
		function() {
			$(this).find('.rollover').stop().fadeTo(400, 1);
		},
		function() {
			$(this).find('.rollover').stop().fadeTo(400, 0);
		}
	)
	
	var menuwindowprefs = "status=1,scrollbars=1,width=660,height=630,resizable=1,menubar=0";
	var menuwindowname = "citygatemenu";


// POPUP LINKS
	$('h2.menu-cocktails a').click(function(event){
		event.preventDefault();
		window.open("/menu-cocktails.php",menuwindowname,menuwindowprefs);
	})
	$('h2.menu-dessert a').click(function(event){
		event.preventDefault();
		window.open("/menu-dessert.php",menuwindowname,menuwindowprefs);
	})
	$('h2.menu-dinner a').click(function(event){
		event.preventDefault();
		window.open("/menu-dinner.php",menuwindowname,menuwindowprefs);
	})
	$('h2.menu-lunch a').click(function(event){
		event.preventDefault();
		window.open("/menu-lunch.php",menuwindowname,menuwindowprefs);
	})
	$('h2.menu-wines a').click(function(event){
		event.preventDefault();
		window.open("/menu-wines.php",menuwindowname,menuwindowprefs);
	})
	$('h2.menu-bar a').click(function(event){
		event.preventDefault();
		window.open("/menu-bar.php",menuwindowname,menuwindowprefs);
	})
	$('h2.menu-beer a').click(function(event){
		event.preventDefault();
		window.open("/menu-beer.php",menuwindowname,menuwindowprefs);
	})

	$('input#email-address').focus(function(event){
		if (this.value == 'EMAIL ADDRESS') {
			this.value = '';
		}
	});
	$('input#email-address').blur(function(event){
		if (this.value == '') {
			this.value = 'EMAIL ADDRESS';
		}
	});
	
	$('#go-button').click(function(event){
		event.preventDefault();
		$('#email-signup').submit();
	})
	
	$('#email-signup').submit(function(event){
		
		var s = $('input#email-address').val();
		var i = 1;
		var hasat = false;

		while (i < s.length) {
			if (s.charAt(i) == "@") {
				hasat = true;
			}
			i++;
		}

		if (s == "" || hasat == false) {
			alert("Please enter a valid email address.");
			return false;
		} else {
		
		var dataString = 'the_address=' + $('input#email-address').val();
  		//alert (dataString);return false;
  		$.ajax({
    		type: "POST",
    		url: "/include/email_submit.php",
    		dataType:'json',
    		data: dataString,
   			success: function(data) {
   				if(data.status == 'ok'){
   					$("#email-signup_cnt").html('');
   					$("#sign-up").append('<p>&nbsp;</p><h2>Thank you.</h2>');   				
   				}else{
   					alert('There was an error in submitting your request.');
   				}
   			

   				/*
      			$('#contact_form').html("<div id=\"message\"></div>");
      			$('#message').html("<h2>Contact Form Submitted!</h2>").append("<p>We will be in touch soon.</p>").hide().fadeIn(1500, function() {
        			$('#message').append("<img id='checkmark' src='images/check.png' />");
      			});
      			*/
      			
    		}
		});
  		return false;
  		}
		return false;
	});
	
	$('input#first-name').focus(function(event){
		if (this.value == 'FIRST NAME') {
			this.value = '';
		}
	});
	$('input#first-name').blur(function(event){
		if (this.value == '') {
			this.value = 'FIRST NAME';
		}
	});
	$('input#last-name').focus(function(event){
		if (this.value == 'LAST NAME') {
			this.value = '';
		}
	});
	$('input#last-name').blur(function(event){
		if (this.value == '') {
			this.value = 'LAST NAME';
		}
	});
	$('input#email-address2').focus(function(event){
		if (this.value == 'EMAIL ADDRESS') {
			this.value = '';
		}
	});
	$('input#email-address2').blur(function(event){
		if (this.value == '') {
			this.value = 'EMAIL ADDRESS';
		}
	});
	$('textarea#comments').focus(function(event){
		if (this.value == 'COMMENTS') {
			this.value = '';
		}
	});
	$('textarea#comments').blur(function(event){
		if (this.value == '') {
			this.value = 'COMMENTS';
		}
	});

	$('#contact-form').submit(function(event){
		
		var validated = true;
		
		if ($('input#first-name').val() == "" || $('input#first-name').val() == "FIRST NAME"){
			validated = false;
		}
		if ($('input#last-name').val() == "" || $('input#last-name').val() == "LAST NAME"){
			validated = false;
		}
		if ($('input#email-address2').val() == "" || $('input#email-address2').val() == "EMAIL ADDRESS"){
			validated = false;
		}
		if ($('textarea#comments').val() == "" || $('textarea#comments').val() == "COMMENTS"){
			validated = false;
		}
	
		
		if (validated) {
		var dataString = 'the_fname=' + $('input#first-name').val() + "&the_lname=" + $('input#last-name').val() + "&the_address=" + $('input#email-address2').val() + "&the_comments=" + $('textarea#comments').val();
		//alert(dataString);

  		$.ajax({
    		type: "POST",
    		url: "/include/contact_submit.php",
    		data: dataString,
    		dataType:'json',
   			success: function(data) {
   				if(data.status == 'ok'){
   					$("#body-copy").html('<p>Thank you for your comments.<br />We will get back to you shortly.</p>');
   				}else{
   					alert('There was an error in submitting your request.');
   				}
   				
      			
    		}
		});
  		return false;
  		} else {
  			alert("Please enter fill out the entire form.");
  			return false;
  		}
  		return false;

	});


	
	$('input#full-name').focus(function(event){
		if (this.value == 'FULL NAME') {
			this.value = '';
		}
	});
	$('input#full-name').blur(function(event){
		if (this.value == '') {
			this.value = 'FULL NAME';
		}
	});
	$('input#email-address3').focus(function(event){
		if (this.value == 'EMAIL ADDRESS') {
			this.value = '';
		}
	});
	$('input#email-address3').blur(function(event){
		if (this.value == '') {
			this.value = 'EMAIL ADDRESS';
		}
	});
	$('input#email-confirm').focus(function(event){
		if (this.value == 'CONFIRM YOUR EMAIL') {
			this.value = '';
		}
	});
	$('input#email-confirm').blur(function(event){
		if (this.value == '') {
			this.value = 'CONFIRM YOUR EMAIL';
		}
	});
	$('input#phone-number').focus(function(event){
		if (this.value == 'PHONE NUMBER') {
			this.value = '';
		}
	});
	$('input#phone-number').blur(function(event){
		if (this.value == '') {
			this.value = 'PHONE NUMBER';
		}
	});

	$('#gift-card-form').submit(function(event){
		
		var validated2 = true;
		
		if ($('input#full-name').val() == "" || $('input#full-name').val() == "YOUR FULL NAME"){
			validated2 = false;
		}
		if ($('input#email-address3').val() == "" || $('input#email-address3').val() == "YOUR EMAIL ADDRESS"){
			validated2 = false;
		}
		if ($('input#email-confirm').val() == "" || $('input#email-confirm').val() == "CONFIRM YOUR EMAIL"){
			validated2 = false;
		}
		if ($('input#phone-number').val() == "" || $('input#phone-number').val() == "YOUR PHONE NUMBER"){
			validated2 = false;
		}
		if ($('input#email-address3').val() != $('input#email-confirm').val()){
			validated2 = false;
		}
		if ($('select#amount option:selected').val() == "none"){
			validated2 = false;
		}
		
		if (validated2) {
		var dataString = 'the_fname=' + $('input#full-name').val() + "&the_address=" + $('input#email-address3').val() + "&the_phone=" + $('input#phone-number').val() + "&the_amount=" + $('select#amount option:selected').val();
		//alert(dataString);

  		$.ajax({
    		type: "POST",
    		url: "/include/giftcard_submit.php",
    		data: dataString,
    		dataType:'json',
   			success: function(data) {
   				if(data.status == 'ok'){
   					$("#body-copy").html('<p>Thank you for your request.<br />We will get back to you shortly.</p>');
   				}else{
   					alert('There was an error in submitting your request.');
   				}
   				
      			
    		}
		});
  		return false;
  		} else {
  			alert("Please enter fill out the form.");
  			return false;
  		}
		return false;
	});





});