$(function(){
	
	//2 day compliment pass
	$('#submit').click(function(){	
		
		$('#loading').remove();
		$('#loader').append('<img src="http://www.beavervalley.ca/wp-content/plugins/contact-form-7/images/ajax-loader.gif" alt="Currently Loading" id="loading"/>');		
			
		// send mail using ajax call
		var firstname = $('#firstname').val();
		var lastname = $('#lastname').val();
		var email = $('#email').val();
		var phone = $('#phone').val();
		var agerange = $('#agerange').val();
		var status = $('#status').val();
		var children = $('#children').val();
		var childrenage = $('#childrenage').val();
		var education = $('#education').val();
		var occupation = $('#occupation').val();
		var homecity = $('#homecity').val();
		var mystory = $('#mystory').val();
		var membershipinfo = $('#membershipinfo').val();

		var ajax2daySend = $.ajax({
			url: 'http://www.beavervalley.ca/wp-content/themes/beavervalley/ajax/2daypass.php',
			type: 'POST',
			data:
				'firstname=' + firstname +
				'&lastname=' + lastname +
				'&email=' + email +
				'&phone=' + phone +
				'&agerange=' + agerange +
				'&status=' + status +
				'&children=' + children +
				'&childrenage=' + childrenage +
				'&education=' + education +
				'&occupation=' + occupation +
				'&homecity=' + homecity +
				'&mystory=' + mystory +
				'&membershipinfo=' + membershipinfo,
			success: 
				function(result_login){
					//alert('hello!!');
					$('#2day-pass-response').html(result_login).hide().fadeIn('slow');
					$('#loading').fadeOut(1000, function(){$(this).remove();});
			}	
		});
		return false;			
		//kill the request 
		ajax2daySend.abort();			
	});
	
	
	
	
	/*mega menu*/
	function megaHoverOver(){
		//$("#rightSide").css("z-index",100);
		//$("#lefSide").css("z-index",50);
		//console.log($(this).attr('id'));
		$(this).find(".sub").stop().fadeTo('fast', 1).show();
		
		strID = $(this).attr('id');
		if(strID.search("_on") == -1){
			if($(this).find(".sub").html()){
				$(this).attr('id', $(this).attr('id') + "_on");
			}
		}
							
		//Calculate width of all ul's
		(function($) { 
			jQuery.fn.calcSubWidth = function() {
				rowWidth = 0;
				//Calculate row
				$(this).find("ul").each(function() {					
					rowWidth += $(this).width(); 
				});	
			};
		})(jQuery); 
		
		if ( $(this).find(".row").length > 0 ) { //If row exists...
			var biggestRow = 0;	
			//Calculate each row
			$(this).find(".row").each(function() {							   
				$(this).calcSubWidth();
				//Find biggest row
				if(rowWidth > biggestRow) {
					biggestRow = rowWidth;
				}
			});
			//Set width
			$(this).find(".sub").css({'width' :biggestRow});
			$(this).find(".row:last").css({'margin':'0'});
			
		} else { //If row does not exist...
			
			//$(this).calcSubWidth();
			//Set Width
			//$(this).find(".sub").css({'width' : rowWidth});
			
		}
	}
	
	function megaHoverOut(){
	  $(this).find(".sub").stop().fadeTo('fast', 0, function() {
		  if($(this).parent().attr('navon') != "_on"){
			  strID = $(this).parent().attr('id');
			  $(this).parent().attr('id', strID.replace("_on", ""));
		  }
		  $(this).hide();
	  });
	  
	}


	var config = {    
		 sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)    
		 interval: 100, // number = milliseconds for onMouseOver polling interval    
		 over: megaHoverOver, // function = onMouseOver callback (REQUIRED)    
		 timeout: 500, // number = milliseconds delay before onMouseOut    
		 out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
	};

	$("ul#topnav li .sub").css({'opacity':'0'});
	$("ul#topnav li").hoverIntent(config);
	/*end mega menu*/
	
	/***********************************************************************
	Accordion
	***********************************************************************/
    lastBlock = $("#a1");
	
	sectionNumber = $("#accordian ul li").length;
	maxWidth = $("#accordian ul li a#a1").width();
    minWidth = (752 - ($("#accordian ul li a#a1").width()*1))/($("#accordian ul li").length-1);
	$("#accordian ul li a.collapsed").css({"width":minWidth+"px", opacity: 0.25 });
	
    $("#accordian ul li a").hover(
      function(){
        $(lastBlock).animate({width: minWidth+"px", opacity: .3 }, { queue:false, duration:400 });
		$(this).animate({width: maxWidth+"px", opacity: 1 }, { queue:false, duration:400});
		lastBlock = this;
      }
    );
	//home page slide show
	$('.homeSlide').cycle({
			fx:		'fade',
			random: 0,
			timeout: 4000,
			delay:	1600
	});
	
	
	//jscroller
	//$jScroller.add("#highlightContainer","#theHighlight","left",1);
	// Add Scroller Object
	$jScroller.add("#scroller_container","#scroller","left",2);
	// Start Autoscroller
	$jScroller.start();

	// homepage testimonial box
	$('#testLink').hoverIntent(
		function(){
			$('#bv_testimonialText').animate({
			  "left": "0"}, 500);
			$('#testRight').animate({
			  "left": "399"
			}, 500);
			
			
		},function(){
			$('#bv_testimonialText').animate({
			  "left": "-367"}, 500);
			$('#testRight').animate({
			  "left": "16px"
			}, 500);
		}
	);

$(".info tr:odd").css("background-color", "#dddddd");
});



