// JavaScript Document
$(document).ready(function(){
	//conditional statement to change bgd according to screen width
	
	
	/*
	$('.tickets').click(function(){
		alert('This Saturday\'s show of \'The Hard Bargain\' is sold out. We hope you will join us for our show on Friday!');
	});
	*/
	
	$('table.striped tr:even').addClass('even');
	//contact form validation
	$('#contactForm').validate({
		rules:{
			name: 'required',
			show: 'required',
			date: 'required',
			email: 
				{
					required: true,
					email: true
					},
			subject: {required: true},
			message: 'required'		
		}, //end of rules
		 messages: {
			  email: {
				 required: "<br/>Please supply an e-mail address",
				 email: "<br/>This is not a valid email address"
			   }
		 }, //end of messages
		errorPlacement: function(error, element) { 
          error.insertAfter(element);
        }
	}); //end of validate
	//
	$('.ticketsForm').validate({
		rules:{
			os1: 'required',
			os2: 'required'
		}, //end of rules
		 messages: {
			os1: "Please tell us which show",
			os2: "Please select a date"
		 }, //end of messages
		errorPlacement: function(error, element) { 
          error.insertAfter(element);
        }
	}); //end of validate
	//
	$('#contactForm input').addClass('required');
	$('#contactForm #email').addClass('email');
	//
	//
	$('#date').datepicker();
	$('#date2').datepicker();
	$('#date3').datepicker();
	$('#date4').datepicker();
	$('.date5').datepicker();
	//
	$('#reservationForm').validate({
		rules:{
			name: 'required',
			show: 'required',
			date: 'required',
			numRes: 'required',
			email: 
				{
					required: true,
					email: true
					},
			subject: {required: true},
			message: 'required'		
		}, //end of rules
		 messages: {
			  email: {
				 required: "<br/>Please supply an e-mail address",
				 email: "<br/>This is not a valid email address"
			   }
		 }, //end of messages
		errorPlacement: function(error, element) { 
          error.insertAfter(element);
        }
	}); //end of validate
	$('#reservationForm input').addClass('required');
	$('#reservationForm #email').addClass('email');
	//
	$('#reservationForm2').validate({
		rules:{
			name: 'required',
			show: 'required',
			date: 'required',
			numRes: 'required',
			email: 
				{
					required: true,
					email: true
					},
			subject: {required: true},
			message: 'required'		
		}, //end of rules
		 messages: {
			  email: {
				 required: "<br/>Please supply an e-mail address",
				 email: "<br/>This is not a valid email address"
			   }
		 }, //end of messages
		errorPlacement: function(error, element) { 
          error.insertAfter(element);
        }
	}); //end of validate
	$('#reservationForm2 input').addClass('required');
	$('#reservationForm2 #email').addClass('email');
	//
							   //
						   //
	$('#ywlRegForm').validate({
		rules:{
			//contact info
			student_name: 'required',
			dob: {required:true,
					date:true},
			tshirt_size: 'required',
			school: 'required',
			parent1_name: 'required',
			address: 'required',
			city: 'required',
			zipcode: {required:true,
						digits:true,
						maxlength:5},
			state: 'required',
			cellphone1: {required:true,
						digits:true,
						maxlength:10},
			email: 
				{
					required: true,
					email: true
					},
			pickup_parent: 'required',		
			//photo release
			permission: {required: true},
			//medical information
			medical_condition: 'required',
			medication: 'required',
			//emergency name
			emergency_name: 'required',
			emergency_phone:  {required:true,
								digits:true,
								maxlength:10},
			//agreement
			agreement: 'required',
			signature_name: 'required',
			signature_date: 'required'
		}, //end of rules
		 messages: {
			  email: {
				 required: "<br/>Please supply an e-mail address",
				 email: "<br/>This is not a valid email address"
			   },
			  permission: "Please select HAS MY PERMISSION or DOES NOT HAVE MY PERMISSION",
			  medication: "Please select YES or NO"
		 }, //end of messages
		errorPlacement: function(error, element) { 
		   if ( element.is(":radio") || element.is(":checkbox")) {
			  error.appendTo( element.parent()); 
			} else {
			  error.insertAfter(element);
			} 
    	} 
		//
		
	}); //end of validate
	//
	//
	//
	
	
	
	
	
	
//google map
$('#mapContent').jmap('init', {
    //mapCenter:[29.473394, -98.525697], this is old Overtime's address
    mapCenter: [29.410113, -98.495592],
	mapZoom:15,
			mapShowjMapIcon: false,
			mapControlSize: 'large',
			mapEnableScaleControl: true,
			mapEnableSmoothZoom: true,
			mapEnableOverview: true,
			mapType: 'map'
			});
$('#mapContent').jmap('addMarker', {pointLatLng:[29.410113, -98.495592]});
//
// jmap directions
	$('#getDirections').submit(function(){
		$('#directions2').empty();
		$('#directions2').append('<p id="closeDir">Close [X]</p>');
		$('#mapContent').jmap('searchDirections', 
		{
			toAddress: '1414 S. Alamo, San Antonio, TX, 78210',
			fromAddress: $('#from').val(),
			directionsPanel: 'directions2'
		});
		var fromAddressValue = $('#from').val();
		if (fromAddressValue==''){
			$('#directions2').empty();
		};
		$('#closeDir').click(function(){
			$('#directions2').empty();
		});
		return false;
	});
//
//
$('#demotable').dataTable({			  
		"aaSorting": [[ 0, "asc" ]],
		"bJQueryUI": true,
		"bStateSave": false,
		"sPaginationType": "full_numbers"
		});
	//
//
$('.hide').hide();
$('.readMore').toggle(
	function(){
		$(this).next('.hide').fadeIn();
	},
	function(){
		$(this).next('.hide').fadeOut();
	}
);	
//
//
$('.icon').hover(
	function(){
		$(this).animate({opacity: 0.3});
	},
	function(){
		$(this).animate({opacity: 1});
	}
);
//
$('.opacity').hover(
	function(){
		$(this).animate({opacity: 0.6});
	},
	function(){
		$(this).animate({opacity: 1});
	}
);
//
$('.nav').superfish();
//
$('#tabs').tabs();
//
//

//
$('#homeAccordion').accordion({
    header:'h2',
	//active: false,
	//event: 'mouseover',
	autoHeight: false
  });
//
$('#homeAccordion h2').hover(
	function(){
		$(this).animate({opacity: 0.3});
	},
	function(){
		$(this).animate({opacity: 1});
	}
);
//
//
$('#homeAccordion .ticketsLink img').hover(
	function(){
		$(this).animate({opacity: 0.3});
	},
	function(){
		$(this).animate({opacity: 1});
	}
);
//
//greybox
	 var gbOptions = {
		gbWidth: 600,
		gbHeight: 300
  		};
$('.bio').greybox(gbOptions);
//
  $(function() {
    $('img.image1').data('ad-desc', 'Whoa! This description is set through elm.data("ad-desc") instead of using the longdesc attribute.<br>And it contains <strong>H</strong>ow <strong>T</strong>o <strong>M</strong>eet <strong>L</strong>adies... <em>What?</em> That aint what HTML stands for? Man...');
    $('img.image1').data('ad-title', 'Title through $.data');
    $('img.image4').data('ad-desc', 'This image is wider than the wrapper, so it has been scaled down');
    $('img.image5').data('ad-desc', 'This image is higher than the wrapper, so it has been scaled down');
    var galleries = $('.ad-gallery').adGallery();
    $('#switch-effect').change(
      function() {
        galleries[0].settings.effect = $(this).val();
        return false;
      }
    );
    $('#toggle-slideshow').click(
      function() {
        galleries[0].slideshow.toggle();
        return false;
      }
    );
    galleries[0].addAnimation('wild',
      function(img_container, direction, desc) {
        var current_left = parseInt(img_container.css('left'), 10);
        var current_top = parseInt(img_container.css('top'), 10);
        if(direction == 'left') {
          var old_image_left = '-'+ this.image_wrapper_width +'px';
          img_container.css('left',this.image_wrapper_width +'px');
          var old_image_top = '-'+ this.image_wrapper_height +'px';
          img_container.css('top', this.image_wrapper_height +'px');
        } else {
          var old_image_left = this.image_wrapper_width +'px';
          img_container.css('left','-'+ this.image_wrapper_width +'px');
          var old_image_top = this.image_wrapper_height +'px';
          img_container.css('top', '-'+ this.image_wrapper_height +'px');
        };
        if(desc) {
          desc.css('bottom', '-'+ desc[0].offsetHeight +'px');
          desc.animate({bottom: 0}, this.settings.animation_speed * 2);
        };
        img_container.css('opacity', 0);
        return {old_image: {left: old_image_left, top: old_image_top, opacity: 0},
                new_image: {left: current_left, top: current_top, opacity: 1},
                easing: 'easeInBounce',
                speed: 2500};
      }
    );
  });
  function debug(str) {
    if(window.console && window.console.log && jQuery.browser.mozilla) {
      console.log(str);
    } else {
      $('#debug').show().val($('#debug').val() + str +'\n');
    }
  }
//
}); //end of jQuery document.ready()