// JS of Rapid Response Users Group (RRUG) 2009
// JavaScript Functions by Todor Iliev
// todoriliev.com


// Preload Images
$(document).ready(function(){
//  $.preloadCssImages();
});


// Banner Rotation
$(document).ready(
	function(){
		$('#rotateBanners').cycle({ 
		fx:     'fade', 
		speed:  'fast', 
		timeout: 0, 
		next:   '#next2', 
		prev:   '#prev2' 
	});
	}
);

// Menu and Drop Downs 
var timeout    = 500;
var closetimer = 0;
var ddmenuitem = 0;

function menu_open()
{  menu_canceltimer();
   menu_close();
   ddmenuitem = $(this).find('ul').css('visibility', 'visible');}

function menu_close()
{  if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

function menu_timer()
{  closetimer = window.setTimeout(menu_close, timeout);}

function menu_canceltimer()
{  if(closetimer)
   {  window.clearTimeout(closetimer);
      closetimer = null;}}

$(document).ready(function()
{  $('#menu > li').bind('mouseover', menu_open)
   $('#menu > li').bind('mouseout',  menu_timer)});

document.onclick = menu_close;

// Registration Form
$(function() {
  $('.error').hide();
  $('input.text-input').css({backgroundColor:"#ffffff"});
  $('input.text-input').focus(function(){
    $(this).css({backgroundColor:"#FFDDAA"});
  });
  $('input.text-input').blur(function(){
    $(this).css({backgroundColor:"#ffffff"});
  });

  $(".button").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();
		
	var firstName = $("input#firstName").val();
		if (firstName == "") {
      $("label#firstName_error").show();
      $("input#firstName").focus();
      return false;
    }
	
	var lastName = $("input#lastName").val();
		if (lastName == "") {
      $("label#lastName_error").show();
      $("input#lastName").focus();
      return false;
    }
	
	var lastName = $("input#title").val();
		if (lastName == "") {
      $("label#title_error").show();
      $("input#title").focus();
      return false;
    }
	
	var lastName = $("input#companyName").val();
		if (lastName == "") {
      $("label#companyName_error").show();
      $("input#companyName").focus();
      return false;
    }
	
	var firstName = $("input#radioGolfing").val();
		if (firstName == "") {
      $("label#radioGolfing_error").show();
      $("input#radioGolfing").focus();
      return false;
    }
	
	var address = $("input#address").val();
		if (address == "") {
      $("label#address_error").show();
      $("input#address").focus();
      return false;
    }
	
	var city = $("input#city").val();
		if (city == "") {
      $("label#city_error").show();
      $("input#city").focus();
      return false;
    }
	
	var state = $("select#state").val();
		if (state == "") {
      $("label#state_error").show();
      $("select#state").focus();
      return false;
    }
	
	var addressZip = $("input#zip").val();
		if (addressZip == "") {
      $("label#zip_error").show();
      $("input#zip").focus();
      return false;
    }
	
	var phone = $("input#phone").val();
		if (phone == "") {
      $("label#phone_error").show();
      $("input#phone").focus();
      return false;
    }
	
	var email = $("input#email").val();
		if (email == "") {
      $("label#email_error").show();
      $("input#email").focus();
      return false;
    }

		
		var dataString = 'firstName='+ firstName + 'lastName='+ lastName + 'title='+ title + 'companyName='+ companyName + 'radioGolfing='+ radioGolfing + 'address='+ address + 'city='+ city + 'state='+ state + 'zip='+ zip + '&phone=' + phone + '&email=' + email;
		//alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "/register/mailer.asp",
      data: dataString,
      success: function() {
        $('#contactForm').html("<div id='confMsg'></div>");
        $('#confMsg').html("<h3>Request Submitted!</h3>")
        .append("<p>We will be in touch soon.</p>")      }
     });
    return false;
	});
});
runOnLoad(function(){
  $("input#firstName").select().focus();
});

var current = 1;

function addPerson() {
	// Current keeps track of how many people we have.
	current++;
	var strToAdd = '<div class="border"><b>Additional Registrant #'+current+'</b></div><div><label for="firstName'+current+'">First Name</label> <input id="firstName'+current+'" name="First Name of Additional Registrant '+current+'" /> </div><div><label for="lastName'+current+'">Last Name</label><input id="lastName'+current+'" name="Last Name of Additional Registrant '+current+'" /></div><div><label for="title'+current+'">Title</label><input id="title'+current+'" name="Title of Additional Registrant '+current+'" /></div><div><label for="phone'+current+'">Phone</label><input id="phone'+current+'" name="Phone of Additional Registrant '+current+'" /></div><div><label for="email'+current+'">Email</label><input id="email'+current+'" name="Email of Additional Registrant '+current+'" /></div><div><label for="package'+current+'">Package</label><select name="Package of Additional Registrant '+current+'" id="package'+current+'"><option value="All Access">All Access ***Best Value*** Package"</option><option value="August 1, 2010 Only">August 1, 2010 Only</option><option value="August 2, 2010 Only">August 2, 2010 Only</option><option value="August 3, 2010 Only">August 3, 2010 Only</option></select></div>'
	
	
	
	strToAdd += '<div><label for="golfing'+current+'">Golfing</label><table class="radio" border="0"><tr><td><input name="Golfing for Additional Registrant '+current+'" type="radio" id="radioGolfingYes'+current+'" value="Yes"/></td><td>Yes</td><td>&nbsp;</td><td><input name="Golfing for Additional Registrant '+current+'" type="radio" id="radioGolfingNo'+current+'" value="Yes" /></td><td>No</td><td>&nbsp;</td></tr></table></div>'
	$('#additionalRegistrant').append(strToAdd)
}

$(document).ready(function(){
	$('#addPerson').click(addPerson)
});



/*
 * Url preview script 
 * powered by jQuery (http://www.jquery.com)
 * 
 * written by Alen Grakalic (http://cssglobe.com)
 * 
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 *
 */
 
this.screenshotPreview = function(){	
	/* CONFIG */
		
		xOffset = 10;
		yOffset = 30;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("a.screenshot").hover(function(e){
		this.t = this.title;
		this.title = "";	
		var c = (this.t != "") ? "<br/>" + this.t : "";
		$("body").append("<p id='screenshot'><img src='"+ this.rel +"' alt='url preview' />"+ c +"</p>");								 
		$("#screenshot")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
		$("#screenshot").remove();
    });	
	$("a.screenshot").mousemove(function(e){
		$("#screenshot")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};


// starting the script on page load
$(document).ready(function(){
	screenshotPreview();
});