// JavaScript Document
$(document).ready(function() {
	var introContainerHeight = 0;
	var introDivisonHeight = 0;
	if($("#intro").length == 1) {	
		NKL.slideshow.init();
		NKL.slideshow.start();
	}
	
	/*
	$("#Contact-submit").click(function() {
		
		$.ajax({
			url: "forms/"+$("#contact-form").attr("action"),
			data: $("#contact-form").serialize(),
			dataType: "text",
			type: "POST",
			beforeSend: function(){
			    // Handle the beforeSend event
					
			},
			success: function(msg){
				// Handle the success event
				if(msg!=="success"){
					if($("#contact-form-ajax").length === 0) {
						$("#Contact-submit").after('<span id="contact-form-ajax">'+msg+'</span>');
					} else {
						$("#contact-form-ajax").html(msg);
					}
				} else {
					if($("#contact-form-ajax").length === 0) {
						$("#Contact-submit").after('<span id="contact-form-ajax">Your message has been sent.</span>') 
					} else {
						$("#contact-form-ajax").html("Your message has been sent.");
					}
				}
			},
			complete: function(){
				// Handle the complete event
				
			},
			error: function() {
				
			}
		});					
		return false;													
	});
	
	$("#startaleague-submit").click(function() {
		$.ajax({
			url: "forms/"+$("#startaleague-form").attr("action"),
			data: $("#startaleague-form").serialize(),
			dataType: "text",
			type: "POST",
			beforeSend: function(){
			    // Handle the beforeSend event
				$("#startaleague-form").find("input").each(function(){
					$(this).attr("disabled","disabled");
				});
				$("#startaleague-submit").after('<span id="startaleague-loading">Sending...</span>');
			},
			success: function(msg){
				// Handle the success event
				$("#startaleague-loading").remove();
				if(msg!=="success"){
					if($("#startaleague-form-ajax").length === 0) {
						$("#startaleague-submit").after('<span id="startaleague-form-ajax">'+msg+'</span>');
					} else {
						$("#startaleague-form-ajax").html(msg);
					}
				} else {
					if($("#startaleague-form-ajax").length === 0) {
						$("#startaleague-submit").after('<span id="startaleague-form-ajax">Your information has been sent, we will get back to you shortly.</span>') 
					} else {
						$("#startaleague-form-ajax").html("Your information has been sent, we will get back to you shortly.");
					}
				}
			},
			complete: function(){
				// Handle the complete event
				$("#startaleague-form").find("input").each(function(){
					$(this).removeAttr("disabled");
					$(this).val("");
				});
			},
			error: function() {
				
			}
		});					
		return false;													
	});
	
	$("#newsletter-submit").click(function() {
		$.ajax({
			url: "forms/"+$("#newsletter-form").attr("action"),
			data: $("#newsletter-form").serialize(),
			dataType: "text",
			type: "POST",
			beforeSend: function(){
			    // Handle the beforeSend event
				$("#newsletter-form").find("input").each(function(){
					$(this).attr("disabled","disabled");
				});
				$("#newsletter-submit").after('<span id="newsletter-loading"><br />Sending...</span>');
			},
			success: function(msg){
				// Handle the success event
				$("#newsletter-loading").remove();
				if(msg!=="success"){
					if($("#startaleague-form-ajax").length === 0) {
						$("#newsletter-submit").after('<span id="newsletter-form-ajax">'+msg+'</span>');
					} else {
						$("#newsletter-form-ajax").html(msg);
					}
				} else {
					if($("#newsletter-form-ajax").length === 0) {
						$("#newsletter-submit").after('<span id="newsletter-form-ajax"><br /><br />Thanks for subscribing!</span>') 
					} else {
						$("#newsletter-form-ajax").html("<br />Thanks for subscribing!");
					}
				}
			},
			complete: function(){
				// Handle the complete event
				$("#newsletter-form").find("input").each(function(){
					$(this).removeAttr("disabled");
					$(this).val("");
				});
			},
			error: function() {
				
			}
		});					
		return false;													
	});
	*/
	if($(".intro-containers").length > 0) {
		$(".intro-containers").each(function(){
			if($(this).height() > introContainerHeight) {
				introContainerHeight = $(this).height();	
			}
		});
		$(".intro-containers").height(introContainerHeight+50);
	}
	
	if($(".intro-divison").length > 0) {
		$(".intro-divison").each(function(){
			if($(this).height() > introDivisonHeight) {
				introDivisonHeight = $(this).height();	
			}
		});
		$(".intro-divison").height(introDivisonHeight);
	}
	
	$("#blog-entries").find("a").each(function(){
		$(this).attr("href","http://nationalkaraokeleague.com/?p=blog").removeAttr("target");										   
	});
	
});

var NKL = NKL || {}
NKL.slideshow = {
	images: '',
	index : 0,
	init : function() {
		images = $("#intro > div.slideshow").children();
		index = 0;
		for(var i = 1; i<images.length; i++) {
			$(images[i]).css("display","none");	
		}		
	},
	
	fade : function(){		
		$(images[index]).fadeOut(2000);
		if(index == images.length-1) {
			index = 0;	
		} else {
			index++;	
		}
		$(images[index]).fadeIn(2000);		
	},
	
	start : function() {
		setInterval(this.fade, 2000);	
	}
	
};

