// JavaScript Document

$.noConflict();
  jQuery(document).ready(function($) {

	var thankyou;
	var baseURL = "/";

	var ie6 = ($.browser.msie && $.browser.version.substr(0,1) < 7);
	
	thankyou = $('#thankyou');

	
	$("#sidebar li a").each(function(i) {
		if (window.location == this.href) {
			
			
			
		
			
			$(this).addClass("selected");	
		}
	});
			 
	$('#email').click(function() {	
		
		$('#window .name').attr("value", "First and Last Name");
		$('#window .email').attr("value", "Email Address");
		
		$('#window').fadeIn(300);
		$('#overlay').removeClass("hide").fadeTo(500, .6);
		return false;
	});
	
	
	$('#close').click(function() {									
		$("#window").fadeOut(300, function() {
			thankyou.remove();
		});
		$("#overlay").fadeTo(500, 0, function() {
			$(this).addClass("hide");
		});	
	});
	
	$('#subscribe').click(function() {	
		subsribe();
		return false;
	});
	
	$('#window form').submit(function() {
		subsribe();
		return false;
	});
	
	$('#window .name').focus(function() {
		if ((this.value) == "First and Last Name") {
			this.value = "";	
		}
	});	
	$('#window .email').focus(function() {
		if ((this.value) == "Email Address" || (this.value) == "Email Address Invalid") {
			this.value = "";
			$(this).removeClass('error');
		}
	});
	
	  
	$("#overlay").fadeTo(0, 0).addClass("hide");
			  
	if (ie6) {
		$(window).resize(function() {
			setOverlayHeight();							  
		});
		setOverlayHeight();
	}
		
	// set rollover states
	$('#home').hover(function() {
			$(this).attr("src", baseURL + "rollover/home.png");		 
		}, function() {
			$(this).attr("src", baseURL + "images/home.png");
		}
	);
	$('#about').hover(function() {
			$(this).attr("src", baseURL + "rollover/about.png");		 
		}, function() {
			$(this).attr("src", baseURL + "images/about.png");
		}
	);
	$('#shop').hover(function() {
			$(this).attr("src", baseURL + "rollover/shop.png");		 
		}, function() {
			$(this).attr("src", baseURL + "images/shop.png");
		}
	);
	$('#resources').hover(function() {
			$(this).attr("src", baseURL + "rollover/resources.png");		 
		}, function() {
			$(this).attr("src", baseURL + "images/resources.png");
		}
	);
	$('#news').hover(function() {
			$(this).attr("src", baseURL + "rollover/news.png");		 
		}, function() {
			$(this).attr("src", baseURL + "images/news.png");
		}
	);
	$('#contact').hover(function() {
			$(this).attr("src", baseURL + "rollover/contact.png");		 
		}, function() {
			$(this).attr("src", baseURL + "images/contact.png");
		}
	);
	
	$('#email').hover(function() {
			$(this).attr("src", baseURL + "rollover/email.png");		 
		}, function() {
			$(this).attr("src", baseURL + "images/email.png");
		}
	);
	$('#share').hover(function() {
			$(this).attr("src", baseURL + "rollover/addthis.png");		 
		}, function() {
			$(this).attr("src", baseURL + "images/addthis.png");
		}
	);
	
	function subsribe() {
	
		var email = $('#window .email');
		
		if (email.attr("value").indexOf("@") != -1 && email.attr("value").indexOf(".") != -1) {										 
		
			$('#window, #subscribe').addClass("loading");	
			$.ajax({
				type: "GET",
				url: "http://studiojeannot.createsend.com/t/r/s/irikiu/",
				dataType: "script",
				data: $('#window form').serialize(),
				success: function(data){
					$('#window, #subscribe').removeClass("loading");
					$('#window:not(#thankyou)').append(thankyou);
					$('#thankyou').hide();
					$('#thankyou').fadeIn(500);
				}
	
			});
	
			
			
		} else {
	
			email.attr("value", "Email Address Invalid");
			email.addClass("error");
		}
	
	}
	
	function setOverlayHeight() {
		$('#overlay').height($("body").height());	
	}
				  
});


