// JavaScript Document

$(document).ready(function(){

	// ads controller

	$("a.ad-controller").click(function(){

										

		$("#ad-container").attr("class", "loading").children('img').fadeOut().parent("#ad-container").empty();							

		var ad_id = parseInt($(this).prevAll().length + 1);

		

		$(".ad-controller").each(function(){  $(this).removeClass("active"); });

		$(this).addClass("active");

		

		var img = new Image();

		// wrap our new image in jQuery, then:

		$(img).load(function () { 

			$(this).hide();

		  	$('#ad-container').removeClass('loading').append(this);

		  	$(this).fadeIn("slow");

		}).attr('src', 'images/our-ads/ad' + ad_id + '.jpg');



	});

	

	// our-media controller

	$("a.media-controller").click(function(){

										

		var controller_id = parseInt($(this).prevAll().length + 1);

		

		$(".media-controller").each(function(){  $(this).removeClass("active"); });

		$(this).addClass("active");

		

		$("#media-content").load('/in-the-media/' + controller_id + '.php');

		

		/*

		var img = new Image();

		// wrap our new image in jQuery, then:

		$(img).load(function () { 

			$(this).hide();

		  	$('#ad-container').removeClass('loading').append(this);

		  	$(this).fadeIn("slow");

		}).attr('src', 'images/our-ads/ad' + ad_id + '.jpg');

		*/

	});

	

	// Block focus controllers
	/*
	$("#oc-block").click(function() { 

		if( $(this).hasClass("active") == false )

		{ 

			$(".mainframe").hide();

			$("#top-our-collection").show();

			$(".sm-block").removeClass("active"); 

			$(this).toggleClass("active"); 

		} 

	}); */

	$("#oa-block").click(function() { 

		if( $(this).hasClass("active") == false )

		{ 

			$(".mainframe").hide();

			$("#top-our-ads").show();

			$(".sm-block").removeClass("active"); 

			$(this).toggleClass("active");

		} 

	});

	$("#om-block").click(function() { 

		if( $(this).hasClass("active") == false )

		{ 

			$(".mainframe").hide();

			$("#top-media").show();

			$(".sm-block").removeClass("active"); 

			$(this).toggleClass("active"); 

		} 

	});

	

	// Newsletter Form submit

	$("#newsletter-submit").click(function(){

										   

		var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;



		var name = $("#newsletter-name").val();

		var email = $("#newsletter-email").val();

		var province = $("#newsletter-state").val();

		

		

		if( (name == "Your Name") || (email == "Your Email") || (province == "Not Specified") )

		{

			alert("Please enter all fields and try again!");

			return false;														 

		} else if(!name)

		{

			alert("Please enter your name and try again!");

			return false;

		} else if( !pattern.test(email) )

		{

			alert("Please enter a valid email address!");	

			return false;

		} else if(!province)

		{

			alert("Please select your state/province and try again!");

			return false;

		} 

		

		$.post("js/ajax/newsletter_api.php", $("#newsletter-signup-form").serialize(),  function(data)

			{

				$("#newsletter-signup span.text").hide().html(data).addClass("bold").fadeIn();

			});

		return false;

		

	});

	

});