//===========================================
// Name: SF Childrens Art Center
// Description: 
// Version: 1.0
// Author: Jeremy Anderson [ Object Adjective ]
// Author URI: http://www.objectadjective.com
//===========================================

//Set ready state
$(document).ready(function(){
   
   //Popup Div Overlay and Handler
   $("#dim").click(function(){
   		closePopDiv();
	});
   $(".close").click(function(event){
   		closePopDiv();
		event.preventDefault();
	});
  
   
   //Gallery Handlers
	$("#thumbs img").bind("mouseenter mouseleave", function(e){
        $(".info-gal").toggleClass("hover");
		$(this).toggleClass("hover");
	});
	$("#thumbs img").click(function(){ //Triggers all img gallery pops
		var src = $(this).attr("src");
		var title = $(this).attr("title");
		src = src.substring(0, src.indexOf('.jpg')) + "_lg.jpg";
		$(".pop").fadeIn('slow').find("img").attr("src", src);
		$(".pop").find("p").text(title);
		popDiv();
	});
	if(document.getElementById("subscribe")){
	$("#subscribe").validate({
		rules: {
			email: {
				required: true,
				email: true
			}
		},
		messages: {
			email: "Please enter a valid email address."
		}
	});
	}
	
	//Expand/Collapse Content
	$(".expand").click(function (event) {
	event.preventDefault();
	$(this).next().next("span").toggle(400);
	});
	$(".description .close").click(function (event) {
	event.preventDefault();
	$(this).parent().toggle(400);
	});
	
	//Query (requires jquery.query.js)
	if(document.getElementById('bodyhome')){
	var cat = $.query.get('cat');
	}
	if(cat == "thank_you"){
		$(".pop").fadeIn('slow');
		popDiv();
	}
   
 });//end ready


// POPUP DIVS

function popDiv() {
		getHeight();
		var browserName = navigator.appName;
		if(browserName == "Microsoft Internet Explorer"){
		$(".pop").css("top", document.documentElement.scrollTop+100+'px');
		}
		else {
		$(".pop").css("top", window.pageYOffset+100+'px');
		}
		$("#dim").show();
}

function closePopDiv(){
	$(".pop").fadeOut('slow');
	$("#dim").hide();
	return false;
}


// Dim Layer for POPUP DIVS

function getHeight(){
	if (parseInt(navigator.appVersion)>3) {
 		if (navigator.appName=="Netscape") {
  		wind = window.innerWidth;
  		wind = window.innerHeight;
 		}
 		if (navigator.appName.indexOf("Microsoft")!=-1) {
  		wind = document.body.offsetWidth;
  		wind = document.body.offsetHeight -136;
 		}
	}
	var divh = document.getElementById('wrapper').offsetHeight;
	var lock = document.getElementById('dim');
	if (divh >= wind){
	lock.style.height = divh +"px";
	}
	else {lock.style.height =wind +"px";}
}


function initSubNav(){
	var current = $("#subnav").find("a").filter(function() { return this.href.toLowerCase() == location.href.toLowerCase(); });
				if ( current.length ) {
					current.addClass("on");
				}
}

$(window).bind("load", function() {
	initSubNav();
	});

