$(document).ready(function() {  		
 /* fix for target="_blank" */
	   $('a[rel*=external]').bind('click', function() {
        window.open(this.href);
	        return false;
	    });
	    
		$("ul.ytPlaylist").ytplaylist({playerWidth:'480', playerHeight:'295',showRelated:false, addThumbs:false, autoPlay:true, holderId:'ytPlayer', allowFullScreen:true});

   $('ul.sf-menu').superfish();
   
   
  $('.item_add').click(function(){
  		$.facebox('<h4 style="text-align:center">Adding to cart…</h4><p style="text-align:center"><img src="/wp-content/themes/necc_v2/images/common/loading_big.gif" /></p>');
  		setTimeout("$.facebox.close()",1000);
  //	setTimeout("$('.simpleCart_finalTotal').animate({ backgroundColor: '#BDE8FF'}, 1000).animate({ backgroundColor: '#ffffff'}, 2000)",1200);

  });
  
  
  // Toggle login panel
 $('#togglePanel').click(function () {
   $(this).toggleClass('open');
    if ($(this).is('.open')){
      $(this).html('Close');
      $('#panel').slideDown(250);
    } else {
     $(this).html('Sign In &#92; Join');
     $('#panel').slideUp(250); 
      
    }
 });

		$(".necc-g1").validate({
	errorElement: "p",
		rules: {
				Name: "required",
				Address: "required",
				City: "required",
				State: "required",
				High_School: "required",
				Grad_year: "required",
				ZIP: {
					number: true,
					required: true,
					minlength: 5,
					maxlength: 5
				},							
				Phone: {
					required: true,
					minlength: 10
				},				
				Home_Phone: {
					required: true,
					minlength: 10
				},	
				Day_Phone: {
					required: true,
					minlength: 10
				},	
				Age: {
					number: true,
					required: true,
					minlength: 1,
					maxlength: 2
				},										
				security_code: {
					required: true,
					minlength: 6,
					maxlength: 6

				},
				Email: {
					required: true,
					email: true
					}
				},
		messages: {
			Name: "Please enter your name",
			Email: "Please enter a valid email address",
			Age: "Please enter a valid age",
			Day_Phone: "Please enter a valid phone number including area code",
			Home_Phone: "Please enter a valid phone number including area code",
			Phone: "Please enter a valid phone number including area code",
			ZIP: "Please enter a valid 5 digit ZIP code",
			security_code: "Please enter the 6 character security code above"
		},
			submitHandler: function(form) { 
		
	 $('form.necc-g1').submit(function() {
				var ajaxResponse = $(this).find('.response');
				var loader = '<div class="spinner floatRight">&nbsp;</div>';
				var formAction = $(this).attr('action');
				var formName = $(this).attr('id');
				var dataString = $("#"+formName+"").serialize();

				ajaxResponse.hide();
    

  $.ajax({
    type: "POST",
    cache: false,
    url: formAction,
    data: dataString,
   	dataType: "json",
   	beforeSend: function(){
						$('#'+formName+' .spinner').show();
						$('#'+formName+' .necc-button').hide();				
	   	},
	   success:  function(data){
    		$('#'+formName+' .spinner').hide();
						$('#'+formName+' .necc-button').show();				
    
		    	if (formName == 'loginform' && data.STATUS == 'success') {   
			     window.location.reload(true);                                                                   
		     } else if (formName == 'coachesform' && data.STATUS == 'success') {   
    					ajaxResponse.html('<p class="'+data.STATUS+'">'+data.MESSAGE+'</p>').fadeIn();
							$('#'+formName+' table').hide();
		     }  else if (formName == 'instructionform' && data.STATUS == 'success') {   
		     			
		     		//	$.scrollTo('.progress-bar');
						//	$('#'+formName+' table').hide();
							window.location = 'http://www.catchingcamp.com/programs/instruction/?p=signup&step=2';
							
							/*
									$('.progress-bar .step1').removeClass('current').addClass('complete');
									$('.progress-bar .step2').addClass('current');
									$('.book-appt').show();		
							*/					
							
				 }  else if (formName == 'contactform' && data.STATUS == 'success') {   
    					ajaxResponse.html('<p class="'+data.STATUS+'">'+data.MESSAGE+'</p>').fadeIn();
							$('#'+formName+' table').hide();
				
				 }  else if (data.STATUS == 'error') {   
    				ajaxResponse.html('<p class="'+data.STATUS+'">'+data.MESSAGE+'</p>').fadeIn();
		     		$.scrollTo('form .response');
		     
		     } else {}
     
     
					}
                
  });

return false;
 
	});
	}
			});

	
	
	
	 $('form.necc-form').submit(function() {
				var ajaxResponse = $(this).find('.response');
				var loader = '<div class="spinner floatRight">&nbsp;</div>';
				var formAction = $(this).attr('action');
				var formName = $(this).attr('id');
				var dataString = $("#"+formName+"").serialize();

				ajaxResponse.hide();
    

  $.ajax({
    type: "POST",
    cache: false,
    url: formAction,
    data: dataString,
   	dataType: "json",
   	beforeSend: function(){
						$('#'+formName+' .spinner').show();
						$('#'+formName+' .necc-button').hide();				
	   	},
	   success:  function(data){
    		$('#'+formName+' .spinner').hide();
				$('#'+formName+' .necc-button').show();				
  
		    	if (formName == 'loginform' && data.STATUS == 'success') {   
							window.location.reload(true);                                                                   
		    	
		    	} else if (formName == 'coachesform' && data.STATUS == 'success') { 
		      		ajaxResponse.html('<p class="'+data.STATUS+'">'+data.MESSAGE+'</p>').fadeIn();
							$('#'+formName+' table').hide();
					
					} else if (formName == 'instructionform' && data.STATUS == 'success') {   
						
							$('#'+formName+' table').hide();
							
							$('.progress-bar .step1').removeClass('current').addClass('complete');
							$('.progress-bar .step2').addClass('current');
							$('.book-appt').show();
							
					} else if (formName == 'contactform' && data.STATUS == 'success') {   
    					
    					ajaxResponse.html('<p class="'+data.STATUS+'">'+data.MESSAGE+'</p>').fadeIn();
							$('#'+formName+' table').hide();

			    }  else if (data.STATUS == 'error') {   
    				ajaxResponse.html('<p class="'+data.STATUS+'">'+data.MESSAGE+'</p>').fadeIn();
		     		$.scrollTo('form .response');
		     
		     } else {}
     
    	}

                
  });

return false;
 
	});
	
	// end JQ
 });
 
 var items=1;
function AddItem() {
  div=document.getElementById("teams");
  button=document.getElementById("add");
  items++;
  newitem="<input name=\"Recent_Team"+ items + "\"" + "type=\"text\"  /> <a href=\"javascript: return true; \" onclick=\" this.parentNode.parentNode.removeChild(this.parentNode);\" title=\"Remove Team\" ><img src=\"/wp-content/themes/necc_v2/images/icons/remove_icon.gif\" border=\"0\" /></a>";
  newitem+="<br /><br />";
  newnode=document.createElement("span");
  newnode.innerHTML=newitem;
  div.insertBefore(newnode,button);
}

  
  function pop(theURL,iHeight,iWidth) {
leftPos = (screen.width) ? (screen.width-iWidth)/2 : 0;
topPos = (screen.height) ? (screen.height-iHeight)/2 : 0;

newWindow = window.open(theURL,'subWindowCustom','toolbar=no,location=no,scrollbars=yes,status=no,menubar=no,resizable=yes,left='+leftPos+',top='+topPos+',height='+iHeight+',width='+iWidth+',fullscreen=no')
newWindow.focus()
}
  


  
  
  
