$(document).ready(function() {
	// fire lightbox
	$("#gallery a").lightBox({containerResizeSpeed: 200});
	
	//clean out images for links
	function cleanImage(n){
		n = n.replace(/ /g,'');
		n = n.toLowerCase();
		return n;
	}


	function imageReplace(n, p){ //n=image p=imageheight
		$img = cleanImage(n.text());
		$last = $img.lastIndexOf("/");		
		// setup rollover.  CSS must be set to overview hidden. 
		n.text("").html("<img src='/~halifaxg/images/menu_"+ $img +".gif' />");		
		n.children("img").css({marginTop:"0px"});
		n.css({display: "block", overflow: "hidden", height: ""+ p + "px"});
		n.hover(function(){
				n.children("img").css({marginTop:"-"+ p + "px"});
			},function(){
				n.children("img").css({marginTop:"0px"});
		});

	}
	
	
	// open close function for sub nav
	function openClose(n, p){
		if(!p){
			n.prev().slideDown(100);
			n.children("span").text('Less');
			n.css({backgroundPosition:"0px -13px"});
			return true;
		}else{
			n.prev().slideUp(100);
			n.children("span").text('More');
			n.css({backgroundPosition:"0px 0px"});
			return false;
		}
	}
	
	
	// fire image replace on the menu items
	$("#mainnav a").each(function(){imageReplace($(this), 48);});
	
	/*-------------- Sub Nav Collapse -------------------*/
	// first we need to create a trigger.
	$("#subnav").after("<div class='more'><span>More</span></div>");
	$("#subnav").hide();
	var $open = false;
	// now lets make this thing actually do something.
	$(".more span").click(function(){
		// open close state
		$open = openClose($(this).parent(), $open);
	});
	

	
	
	// print and font items
	//setup font buttons
	$("#imageheader").after("<div id='fontcontrol'><span class='makesmall'><img src='/~halifaxg/images/btn_text_small.gif' alt='Make Text Smaller' /></span><span class='makelarge'><img src='/~halifaxg/images/btn_text_large.gif' alt='Make text larger' /></span><span class='printpage'><img src='/~halifaxg/images/btn_print.gif' alt='print page' /></span></div>");
	//setup global for font size
	var $globalsize = 1.0;
	$(".makesmall").click(function(){
		if($globalsize >= 0.8){
		$globalsize = $globalsize - .2;
		$("#news, #content").css({fontSize: $globalsize + "em"});
		}
	});
	$(".makelarge").click(function(){
		if($globalsize <= 1.2){
		$globalsize = $globalsize + .2;
		$("#news, #content").css({fontSize: $globalsize + "em"});
		}
	});
	$(".printpage").click(function(){
		window.print();
	});
	/* setup twitter feed */
	$("#twitter").getTwitter({
		userName: "Greater_Halifax",
		numTweets: 1,
		loadText: "Loading",
		slideIn: false,
		showHeading: true,
		headingText: "Follow us on:",
		showProfileLink: true
	});
	
	$("#faqlisting>div:even").css({
		padding: "10px"
	});
	$("#faqlisting>:odd").css({padding: "10px"});
	
});