// city dropdown box 
$(document).ready(function(){
	$(".change_city").live('click',function() { //When trigger is clicked...
		//Following events are applied to the subnav itself (moving subnav up and down)
		if($(this).parent().find("ul.subnav").hasClass('expanded')){
			$(this).parent().find("ul.subnav").delay(400).slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
			$(this).parent().find("ul.subnav").removeClass('expanded'); //Drop down the subnav on click
			$('.change_city span').css('background-position', 'center top');
		}else{
			$(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click
			$(this).parent().find("ul.subnav").addClass('expanded'); //Drop down the subnav on click
			$('.change_city span').css('background-position', 'center bottom');
		}
		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() {
			$(this).addClass("subhover"); //On hover over, add class "subhover"
			
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
		});
});

$(document).ready(function(){
		/* Email List LINK */
		$(".email_list_link").fancybox({
			'overlayOpacity': .8,
			'overlayColor'  : '#0F0F0F',
			'scrolling'		: 'no',
			'titleShow'		: false,
			'hideOnOverlayClick': false,
			'content' : $('#form_container #email_listform'),
			'onComplete'		: function() {
				$('#email_error').hide();
				$('#list_error').hide();
				$('#successmsg').hide();
				$('#city_select').removeAttr('selected');
				$('#fname_input').val('');
				$('#lname_input').val('');
				$('#email_input').val('');
				$('#email_listform').show();
			}
		});

/* Email List Validation */
$("#email_btn").live("click", function() {
	var error = false;
	
	if ($("#city_select").val() == "") {
		error = true;
	}
	
	if ($("#fname_input").val() == ""){
		error = true;
	}
	
	if ($("#lname_input").val() == ""){
		error = true;
	}
	
	if ($("#email_input").val() == ""){
		error = true;
	}
	
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if(reg.test($("#email_input").val()) == false) {
		error = true;
	}
	
	reg = /^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*$/;
	if(reg.test($("#fname_input").val()) == false) {
		error = true;
	}
	if(reg.test($("#lname_input").val()) == false) {
		error = true;
	}
	
	if (error == true){
		$("#email_error").show();
	    $.fancybox.resize();
	    return false;
	}else{
		
		$.post(
				"../../join_email_list.php",  // ajax php script //
				{ 
					//VARIABLES
					city: $("#city_select").val(),       
					fname: $("#fname_input").val(),       
					lname: $("#lname_input").val(),    
					email: $("#email_input").val()
				},
				// function that works once the data is returned
				function(data){
					successful = data.successful[0];	
					if (successful == "true"){
						$("#email_error").hide();
						$("#email_added").show();
						$("#list_error").hide();
						$("#email_listform table").hide();
						$("#email_btn").hide();
						$.fancybox.resize();
					}else if(successful == "false"){
						$("#email_error").hide();
						$("#list_error").show();
						$.fancybox.resize();
					}else if(successful == "wrong_info"){
						$("#list_error").hide();
						$("#email_error").show();
						$.fancybox.resize();
					}
					
				}, 
				// data type
				"json"
			);
		
	}
	return false;
	
});

// I want to
$(document).ready(function(){
	$("#i_wanna").live('click',function() { //When trigger is clicked...
		//Following events are applied to the subnav itself (moving subnav up and down)
		if($(this).find("ul.subnav").hasClass('expanded')){
			$(this).find("ul.subnav").delay(400).slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
			$(this).find("ul.subnav").removeClass('expanded'); //Drop down the subnav on click
			$('#i_wanna span').css('background-position', 'center top');
		}else{
			$(this).find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click
			$(this).find("ul.subnav").addClass('expanded'); //Drop down the subnav on click
			$('#i_wanna span').css('background-position', 'center bottom');
		}
		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() {
			$(this).addClass("subhover"); //On hover over, add class "subhover"
			
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
			
	});

});

		
});


// Expanding Boxes
$(document).ready(function(){
	
  $('.info-link').click(function() {
	
	 if ($("#current_season_info").hasClass('expanded')){ 
		 $('.expanded').slideUp(300);
		 $('.expanded').removeClass('expanded');
	 }else{
		 $('.expanded').slideUp(300)
		 $('.expanded').removeClass('expanded');
		 var data = $('#current_season_info').html();
			$("#current_season_info").hide().html(data).delay(300).slideDown().show(function(){
				$(this).html(data).show();
				$("#current_season_info").addClass('expanded');
			});
		 
	 } 
    return false;
  });
  
   $('.view_sns').click(function() {
	   var elementClicked = $(this).attr("href");
	   var destination = $(elementClicked).offset().top;
	   $("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination-20}, 500 );
	   $('.expanded').slideUp(300)
	   $('.expanded').removeClass('expanded');
	   var data = $('#current_season_info').html();
		$("#current_season_info").hide().html(data).delay(300).slideDown().show(function(){
				$(this).html(data).show();
				$("#current_season_info").addClass('expanded');
			});
    return false;
  });
  
  $('#upcoming-link').click(function() {
	 if ($("#upcoming_season_info").hasClass('expanded')){ 
		 $('.expanded').slideUp(300);
		 $('.expanded').removeClass('expanded');
	 }else{
		 $('.expanded').slideUp(300)
		 $('.expanded').removeClass('expanded');
		 $("#upcoming_season_info").delay(300).slideDown(310)
		 $("#upcoming_season_info").addClass('expanded');
	 }
    return false;
  });
  
  $('.view_upcoming_season').click(function() {
	  var elementClicked = $(this).attr("href");
	   var destination = $(elementClicked).offset().top;
	   $("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination-20}, 500 );
	 if ($("#upcoming_season_info").hasClass('expanded')){ 
		 $('.expanded').slideUp(300);
		 $('.expanded').removeClass('expanded');
	 }else{
		 $('.expanded').slideUp(300)
		 $('.expanded').removeClass('expanded');
		 $("#upcoming_season_info").delay(300).slideDown(310)
		 $("#upcoming_season_info").addClass('expanded');
	 }
    return false;
  });
  
  
  
  $('.close img').click(function() {
     $('.expanded').slideUp(300);
     $('.expanded').removeClass('expanded');
    return false;
  });
  
  $('.close img').live('click',function() {
     $('.expanded').slideUp(300);
     $('.expanded').removeClass('expanded');
    return false;
  });
  
  
 });
 
 // news fancybox

 $('.news-link').live('click',function(){
	return false;
 });
 $('.inline').live('click',function(){
	
	return false;
 });
 
$(document).ready(function() {
	$('#availableleagueslink').attr('href','#availableleagues');
	/* This is basic - uses default settings */
	$(".news-link").fancybox({
			'overlayColor':'#0F0F0F'
		});
		
	/* This is basic - uses default settings */
	$("#availableleagueslink").live('click',function(){
		var content = $('#availableleagues').html();
		$.fancybox({
			'overlayOpacity': .8,
			'overlayColor'  : '#0F0F0F',
			'titleShow'		: true,
            'content' : '<div class="whitebg">'+content+'</div>'
            });
	});
	$('#leaguebarlink').live('click',function(){
		var content = $('#leaguebar').html();
		$.fancybox({
			'overlayOpacity': .8,
			'overlayColor'  : '#0F0F0F',
			'titleShow'		: true,
            'content' : '<div class="whitebg">'+content+'</div>'
            });
	});
});


 // iframe fancybox
 $(document).ready(function() {
	 $('.iframe').live('click',function(){
		 $(this).fancybox({
			'overlayColor':'#0F0F0F',
			'width' : 800,
			'height': 550,
			'hideOnOverlayClick':false,
			 'onClosed': function() {
				parent.location.reload(true); ;
			  }
		 });
		return false;
	 });

	$(".iframe").fancybox({
			'overlayColor':'#0F0F0F',
			'width' : 800,
			'height': 550,
			'hideOnOverlayClick':false,
			 'onClosed': function() {
				parent.location.reload(true); ;
			  }
		});
		
	return false;
	
});

 $(document).ready(function() {
	 $('.iframe2').live('click',function(){
		 $(this).fancybox({
			'overlayColor':'#0F0F0F',
			'type':'iframe',
			'hideOnOverlayClick':false,
			'width' : 800,
			'height': 550
		 });
		return false;
	 });

	$(".iframe2").fancybox({
			'overlayColor':'#0F0F0F',
			'type':'iframe',
			'hideOnOverlayClick':false,
			'width' : 755,
			'height': 550
		});
		
	return false;
	
});



 
 // all text inputs trick
$(document).ready(function(){
	$('input[type=text], input[type=password]').each(function(){
		var val = $(this).val();
		$(this).focus(function(){
			if($(this).attr('value') == val){
				$(this).val('');
			}				
		});	
		$(this).blur(function(){
			if($(this).attr('value') == ''){
				$(this).val(val);
			}				
		});	
	});
	

	$('a[rel="tooltip1"]').click(function(){
		$('.tooltip').hide();
		$('#tooltip1').show();
		$('#tooltip1').css('opacity','0');
		$('#tooltip1').css('top','-300px');
		$('#tooltip1').animate({opacity:'1'},{queue:false, duration:400 });
		$('#tooltip1').animate({top:'-60px'},{queue:false, duration:300 });
		$('#tooltip1 .park-name').html($(this).html());
		return false;
		//alert($(this));
	});
	$('a[rel="tooltip2"]').click(function(){
		$('.tooltip').hide();
		$('#tooltip2').show();
		$('#tooltip2').css('opacity','0');
		$('#tooltip2').css('top','-300px');
		$('#tooltip2').animate({opacity:'1'},{queue:false, duration:400 });
		$('#tooltip2').animate({top:'-35px'},{queue:false, duration:300 });
		$('#tooltip2 .park-name').html($(this).html());
		return false;
		//alert($(this));
	});
	$('a[rel="tooltip3"]').click(function(){
		$('.tooltip').hide();
		$('#tooltip3').show();
		$('#tooltip3').css('opacity','0');
		$('#tooltip3').css('top','-300px');
		$('#tooltip3').animate({opacity:'1'},{queue:false, duration:400 });
		$('#tooltip3').animate({top:'-5px'},{queue:false, duration:300 });
		$('#tooltip3 .park-name').html($(this).html());
		return false;
	});	
	$('a[rel="tooltip4"]').click(function(){
		$('.tooltip').hide();
		$('#tooltip4').show();
		$('#tooltip4').css('opacity','0');
		$('#tooltip4').css('top','-300px');
		$('#tooltip4').animate({opacity:'1'},{queue:false, duration:400 });
		$('#tooltip4').animate({top:'15px'},{queue:false, duration:300 });
		$('#tooltip4 .park-name').html($(this).html());
		return false;
	});	
	$('a[rel="tooltip5"]').click(function(){
		$('.tooltip').hide();
		$('#tooltip5').show();
		$('#tooltip5').css('opacity','0');
		$('#tooltip5').css('top','-300px');
		$('#tooltip5').animate({opacity:'1'},{queue:false, duration:400 });
		$('#tooltip5').animate({top:'35px'},{queue:false, duration:300 });
		$('#tooltip5 .park-name').html($(this).html());
		return false;
	});	

	
	$('.tooltip').click(function(){
		$(this).hide();
		return false;
	});
	$('.closebtn a').click(function(){
		$('.tooltip').hide();
		return false;
	});	
 });	
 
$(document).ready(function(){
 
//  FLICKR STUFF
	
	//set first image
	$('#flickr-large img').attr('src', $('#flickr-thumbs a').attr('href'));
	//manage thumbs
	$('#flickr-thumbs ul li a').click(function(){
		$('#flickr-large img').attr('src', $(this).attr('href'));
		$('#flickr #loading').show();
		return false;
	});
	
	

		
		$('#referrals-thumbs ul li a').click(function(){
		var vid = $(this).attr('href');
		vid = vid.replace("http://www.referrals.com/watch?v=", "http://www.referrals.com/v/");
		
		var referralsSO = new SWFObject(vid,"ply","395","240","9","#FFFFFF");
		referralsSO.addParam('wmode','transparent');
		referralsSO.write("current-video");
		
		return false;
	}); 

// YOUTUBE STUFF
	var video_id;$(".youtube_link").click(function(){video_id=$(this).attr("id");$("#video_placeholder").empty();$("#video_placeholder").append('<object width="395" height="240"><param name="movie" value="http://www.youtube.com/v/'+video_id+'&hl=en_US&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'+video_id+'&hl=en_US&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="395" height="240"></embed></object>');return false});
});
