$('html').addClass('hasjs')

Cufon.replace('h3 a, h2 a, h6, .more, h4, #learnmore li, #inav a', {
	hover: true,
	fontFamily: "Trade"
});

Cufon.replace('#footer h3, h1, #pagecontent h3, .faqs li h6 span, .faqs .answer span', {
	hover: true,
	fontFamily: "Knockout"
});

var $j = jQuery.noConflict();
$j(document).ready(function() {

	if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {} else {
		$j('.section:not(#register-section, #learnmore, #register-sidebar, .home #rightCol)').fadeTo(0, 0.45);
	
		$j('.section:not(#register-section, #learnmore, #register-sidebar)').hover(function(){
			$j(this).fadeTo(300, 1);
		},function(){
			$j(this).fadeTo(300, 0.45);
		});
	}

	// flash player
		
	// end flash player

	// home page interface animation
	$j('#home-interface .image:first').clone().insertAfter('.hi1').removeClass('hi1').addClass('hi2');
	$j('#home-interface .image:first').clone().insertAfter('.hi2').removeClass('hi1').addClass('hi3');
	$j('#home-interface .image:first').clone().insertAfter('.hi3').removeClass('hi1').addClass('hi4');
	$j('#home-interface .image:first').clone().insertAfter('.hi4').removeClass('hi1').addClass('hi5');
	$j('#home-interface .image').delay('3000').animate({
		width: '0px'
		}, 500, function(){
			$j(this).remove();
			$j('.home .video').each(function(){			
				var file = $j(this).attr('id');
				var srcfile = $j('#' + file + '').attr('rel');
				//console.log(file);
				//console.log(srcfile);
				
				var s1 = new SWFObject('http://proball.bustbright.com/frontend/jw-player/player.swf','player','478','325','9');
				s1.addParam('allowfullscreen','true');
				s1.addParam('allowscriptaccess','always');
				s1.addParam('bufferlength','1800');
				s1.addVariable('file',srcfile);
  				s1.addVariable('autostart','true');
				s1.write('' + file + '');
			});
	});
	// end home page interface animation
	
	//
	$j('#icontent #panel1').addClass('selected');
	$j('#panel2, #panel3, #panel4, #panel5').fadeOut(0);
	$j('#inav li a:not(#registeriface a, #paymentiface a)').click(function(){
		//$j('#inav .selected').removeClass('selected');
		$j('#inav .selected').animate({'padding-left': '-=34px'}, 400, function(){
			$j(this).removeClass('selected');
		});
		
		$j(this).parent('li').animate({'padding-left': '34px'}, 400, function(){
			$j(this).addClass('selected');
		})
		
		var panel = $j(this).attr('href');
		//console.log(panel);
		$j('.panel.selected').fadeOut(400).removeClass('selected');
		$j('' + panel + '').fadeIn(400).addClass('selected');
		
		
		return false;
	});
	//
	
	//column height fix
	if( $j('#leftCol').height() < $j('#rightCol').height() ){
		var h = $j('#rightCol').height() - $j('#leftCol #pagehead').height() -80;
		//console.log(h);
		$j('#leftCol #pagecontent').height(h);
	} 
	else if( $j('.home #rightCol').height() < $j('.home #leftCol').height() ){
		var h = $j('#leftCol').height() -75;
		//console.log(h);
		$j('#rightCol').height(h);
	}
	// end window height fix
	
	
	//coachesbio & faqs accordion
	$j('.coachbio .coachhide, .faqs #pagecontent .answer').slideUp(0);

	$j('.coachlist li').click(function(e){
		if( $j(e.target).is('.coachlist li *:not(embed, p)') ){
			if($j(this).find('.coachhide').is(':visible')) {
				$j(this).find('.coachhide').slideUp(300);
			} else {
				$j(this).find('.coachhide').slideDown(300);
			}
		}
		return false;
	});
	
	$j('.faqs #pagecontent li').click(function(e){
		if( $j(e.target).is('.answer a') ){} else {
			if($j(this).find('.answer').is(':visible')) {
				$j(this).find('.answer').slideUp(300);
			} else {
				$j(this).find('.answer').slideDown(300);
			}
			return false;
		}
	});
	//end coachesbio & faqs accordion
	
	//coaches bio videos
	$j('.coachbio .vidreplace').each(function(){			
			var file = $j(this).attr('id');
			var srcfile = $j(this).attr('rel');
			//console.log(file);
			//console.log(srcfile);
			
			var s1 = new SWFObject('http://proball.bustbright.com/frontend/jw-player/player.swf','player','375','255','9');
			s1.addParam('allowfullscreen','true');
			s1.addParam('allowscriptaccess','always');
			s1.addVariable('file',srcfile);
			s1.write('' + file + '');
		});
	// end coach videos

	//lightbox
		$j('#videolist li a').click(function(){
			//longTail(url, dims, 'player');
			if ($j('#lightboxwall').length == 0) {
				$j('body').append('<div id="lightboxwall"><div id="lightbox"><div class="lbcontent"><div id="vidplayer"></div></div><div class="lbinfo"><a class="removelightbox" href="#">close this</a><h1>Batting Practice</h1><p class="caption">Lorem Ipsum.</p><a class="prev" href="">Previous Video</a><a class="next" href="">Next Video</a></div></div></div>');
				
				var h = $j('.lbcontent').height();
				h = h -75;
				//console.log(h);
				$j('.lbinfo').height(h);
				Cufon.replace('h1', {fontFamily: "Knockout"});
				
				$j('#lightboxwall').fadeTo(500, 1);
				var s1 = new SWFObject('http://proball.bustbright.com/frontend/jw-player/player.swf','player','600','480','9');
				s1.addParam('allowfullscreen','true');
				s1.addParam('allowscriptaccess','always');
				s1.addParam('wmode','opaque');
				s1.addParam('flashvars','file=video.flv&autostart=true');
				s1.write('vidplayer');	
			}
			return false;
		});
		
		$j('#photolist li a, #gallery-151 a').click(function(){
			//console.log('test');
			
			var url = $j(this).attr('href');
			var title = $j(this).find('img').attr('title')
			var caption = '';
			
			if ($j('#lightboxwall').length == 0) {
				$j('body').append('<div id="lightboxwall"><div id="lightbox"><div class="lbcontent"><img src="' + url +'" alt="" /></div><div class="lbinfo"><a class="removelightbox" href="#">close this</a><h1>' + title + '</h1><p class="caption">'+ caption + '</p></div></div></div>');
				
				//<a class="prev" href="">Previous Photo</a><a class="next" href="">Next Photo</a>
				
				var h = $j('.lbcontent').height();
				h = h -75;
				//console.log(h);
				$j('.lbinfo').height(h);
				Cufon.replace('h1', {fontFamily: "Knockout"});
				
				$j('#lightboxwall').fadeTo(500, 1);
			}
			return false;
		});
		
		$j("a.removelightbox, #lightboxwall").live("click", function(e) {
			if( $j(e.target).is('#lightbox *:not(.removelightbox)') ){
			} else {
				$j('#lightboxwall').fadeOut(500, function(){
					$j(this).remove();
				});
			}
		})
	//
	
	//Form Submit
	$j(".register form button").live('click', function() {
		
		$j(this).attr('disabled', 'disabled').after('<p class="status">Processing Your Registration...</p>');
      // validate and process form here
      $j(".error").removeClass('error');
      
      $j('.register .required').each(function(){
      	//console.log($j(this).val());
      	if($j(this).val() == '') {
      		$j(this).prev('label').append('<span class="error"> required</span>');
      		$j(this).focus();
      		$j(".register form button").attr('disabled', '');
      		return false;
      	} else {
      		if( $j('#coupon1').val() == 'SCPB2010' ){
      			var referCode = 'SCPB2010';
      		}
      		var dataString = $j(".register form").serialize();
			    $j.ajax({
			    		type: "POST",
			    		url: "http://pro-ball.com/index/insert.php?action=registration", //Insert processing file here.
			    		data: dataString,
			    		success: function() {
			      		$j('.register #pagecontent').html('<div id="message"><h4>Thank you!</h4><p>Your Registration has been submitted.</p><h4>Payment Options</h4><p>A deposit of $500 dollars of required to hold your spot at the Clinic. You can pay by PayPal or a check</p><p>To make a payment via Check/Money <a href="../pdf/registration-form.pdf?page=thankyou">Click Here</a></p></div>');
			      		if(referCode = 'SCPB2010') {
			      			$j('#message').append('<div><form action="https://www.paypal.com/cgi-bin/webscr" method="post"><input type="hidden" name="cmd" value="_s-xclick"><input type="hidden" name="hosted_button_id" value="A23SW786BHPZJ"><input type="image" src="https://www.paypal.com/en_US/i/btn/btn_paynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"><img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"></form></div>');
			      		} else {
			      			$j('#message').append('<div><form action="https://www.paypal.com/cgi-bin/webscr" method="post"><input type="hidden" name="cmd" value="_s-xclick"><input type="hidden" name="hosted_button_id" value="A23SW786BHPZJ"><input type="image" src="https://www.paypal.com/en_US/i/btn/btn_paynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!"><img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"></form></div>');
			      		}
			      		$j('#register-sidebar p').remove();
			      		Cufon.replace('h4', { fontFamily: "Trade" });
					    }, 
					    error: function(XMLHttpRequest, textStatus, errorThrown) {
					    	$j('.status').addClass('error').html('There was an error processing your request. Please try again. If you still cannot submit your registration, please contact us.');
					    }
					  });
					  return false;
      	}
      });
            
   return false; 
   });
	// End Form Submit

});
