$j = jQuery.noConflict();

$j(document).ready(function()
{
	
	// Gravity forms luncheon form.
	var ticket_choice = '#choice_1_0',
			presenting_sponsor = '#choice_5_0',
			gold_sponsor = '#choice_7_0',
			silver_sponsor = '#choice_9_0',
			total_sponsors = presenting_sponsor + ',' + gold_sponsor + ',' + silver_sponsor;
			
	$j( total_sponsors ).live( 'click', function(){
		
		$j( total_sponsors ).attr( 'checked', '' );
		$j( this ).attr('checked', 'checked' );
		
	});
			
			
	/* Input Value */
	$j('input').each(function() {
     
		var default_value = this.value;
		  
		if( $j(this).is('.submit, .button') ){
		  	// Do Nothing
		}else{
		   $j(this).focus(function() {
		       if(this.value == default_value) {
		           this.value = '';
		       }
		   });
		   $j(this).blur(function() {
		       if(this.value == '') {
		           this.value = default_value;
		       }
		   });
		}
  });
	
	
	$j('#slideshow').cycle({
			fx: 'fade' // choose your transition type, ex: fade, scrollUp, shuffle, etc...
		});
	
	$j('#celebrate-slideshow').fadeIn('800', function(){
		$j('#celebrate-slideshow').cycle({
			fx: 'fade',
			speed: 800,
			timeout: 800.
		});
	});

	$j("input[type=checkbox]").addClass("checkbox");
	//hide the all of the element with class msg_body
	//$j("#email-popup").hide();
	//$j("#email-popup2").hide();
	
  	//toggle the componenet with class msg_body
  	$j("#email-button").click(function()
  	{
  	
    	$j("#email-popup").slideToggle(300);
    	
  	});
  	
  	$j("#email-button2").click(function(){
    	
    	$j("#email-popup2").slideToggle(300);
    	
  	});
	
	k_form2(); //initialize the form
	
});


function k_form2(){
	
	
		var template_url = $j("meta[name=twicet3]").attr('content');
		var my_error;
		
		$j(".ajax_form2 #send").bind("click", function(){
			my_error = false;
				
					
				var value = $j(this).attr("value");
				var check_for = $j(this).attr("id");
				var surrounding_element = $j(this).parent();
				
				if(check_for == "yourEmail"){
				
					if(!value.match(/^\w[\w|\.|\-]+@\w[\w|\.|\-]+\.[a-zA-Z]{2,4}$/)){
						surrounding_element.attr("class","").addClass("error");
						my_error = true;
					}else{
						surrounding_element.attr("class", "").addClass("valid");
					}
					
				}//Check email function
				
				if(check_for == "yourMessage" || check_for == "yourEmail" || check_for == "friendEmail"){
					
					if(value == ""){
						surrounding_element.attr("class","").addClass("error");
						my_error = true;
					}else{
						surrounding_element.attr("class","").addClass("valid");
					}
					
				}//End Check other fields
				
				if(my_error == false){
				
					$j(".ajax_form2").slideUp(400);
					
					var $datastring = "ajax=true";
					
					$j(".ajax_form2 input, .ajax_form2 textarea").each(function(i)
					{
						
						if($j(this).attr('name') == 'Send'){
							
							var $name = $j(this).attr('name');	
							var $value = $j(this).attr('value');
							$datastring = $datastring + "&" + $name + "=" + $value;
							return false;
							
						}else{
							
							var $name = $j(this).attr('name');	
							var $value = $j(this).attr('value');
							$datastring = $datastring + "&" + $name + "=" + $value;	
							
						}
						
					});//.each function
					
					$j(".ajax_form2 #send").fadeOut(100);
					
					$j.ajax({
					   type: "POST",
					   url: template_url+"/send2.php",
					   data: $datastring,
					   success: function(response){
							   $j(".ajax_form2").before("<div class='ajaxresponse' style='display: none;'></div>");
							   $j(".ajaxresponse").html(response).slideDown(400); 
							   $j(".ajax_form2 #send").fadeIn(400);
							   $j(".ajax_form2 #yourEmail, .ajax_form2 #friendEmail, .ajax_form2 #yourMessage").val("");
						}
					});//ajax function

				}//if my_error		
				
			return false;
			
		});// End bind(function)

	
}// End K2Form

