// JavaScript Document

$(document).ready(function(){
	
	// Set the current year for the copywright notice
    var theYear = new Date().getFullYear();
     $('#curYear').text(theYear);
	
	
	
	// Validate the contact form
	$("#subFormBut").click(function(){
		$(".error").hide();
		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;


		var rbtTestVal = $("#fld-8050").val();
		if(rbtTestVal != '') {
			hasError = true;
		}
		
		
		var messageVal = $("#message").val();
		if(messageVal == '') {
			$("#lblMessage").append('<span class="error">Please enter the message.</span>');
			$("#message").focus();
			hasError = true;
		}
		
		
		var emailVal = $("#email").val();
		if(emailVal == '') {
			$("#lblEmail").append('<span class="error">Please enter your email. Confidential... I promise.</span>');
			$("#email").focus();
			hasError = true;
		} else if(!emailReg.test(emailVal)) {
			$("#lblEmail").append('<span class="error">Please enter a valid email. Confidential... I promise.</span>');
			$("#email").focus();
			hasError = true;
		}
		

		var nameVal = $("#name").val();
		if(nameVal == '') {
			$("#lblName").append('<span class="error">Please enter your name.</span>');
			$("#name").focus();
			hasError = true;
		}

		
		if (hasError == false) {
			var msgString = messageVal.replace("&","and");
			var dataString = 'name='+ nameVal + '&email=' + emailVal + '&message=' + msgString;  
			$("#contact-form").html("<div id='loading'><img src='/assets/img/ajax-loader.gif' alt='processing now...' /></div>");
			$.ajax({
			url: 'contact-conf.php',
			type: 'POST',   
			data: dataString,
			success: function(responseText){
				$("#contact-form").fadeOut("fast", function(){$("#contact-form").html(responseText);});
				$("#contact-form").fadeIn("fast");
				}
			});
					
			return false;
	
		}
		else {
			return false;
		}
	});
	

  $('.bubbleInfo').each(function () {
    // options
    var distance = 20;
    var time = 250;
    var hideDelay = 500;

    var hideDelayTimer = null;

    // tracker
    var beingShown = false;
    var shown = false;
    
    var trigger = $('.trigger', this);
    var popup = $('.popup', this).css('opacity', 0);

    // set the mouseover and mouseout on both element
    $([trigger.get(0), popup.get(0)]).mouseover(function () {
      // stops the hide event if we move from the trigger to the popup element
      if (hideDelayTimer) clearTimeout(hideDelayTimer);

      // don't trigger the animation again if we're being shown, or already visible
      if (beingShown || shown) {
        return;
      } else {
        beingShown = true;

        // reset position of popup box
        popup.css({
          top: -125,
          left: -150,
          display: 'block' // brings the popup back in to view
        })

        // (we're using chaining on the popup) now animate it's opacity and position
        .animate({
          top: '-=' + distance + 'px',
          opacity: 1
        }, time, 'swing', function() {
          // once the animation is complete, set the tracker variables
          beingShown = false;
          shown = true;
        });
      }
    }).mouseout(function () {
      // reset the timer if we get fired again - avoids double animations
      if (hideDelayTimer) clearTimeout(hideDelayTimer);
      
      // store the timer so that it can be cleared in the mouseover if required
      hideDelayTimer = setTimeout(function () {
        hideDelayTimer = null;
        popup.animate({
          top: '-=' + distance + 'px',
          opacity: 0
        }, time, 'swing', function () {
          // once the animate is complete, set the tracker variables
          shown = false;
          // hide the popup entirely after the effect (opacity alone doesn't do the job)
          popup.css('display', 'none');
        });
      }, hideDelay);
    });
  });





});

