$(document).ready(function() {
	// fire lightbox
	  //      $(document).pngFix(); 
	//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='/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"});
		});
	}

	var coords = new Object;
	function mousePos(evt, n){
		// find mouse position inside document upon event propagation.
		var x = (evt.pageX - n.parentNode.parentNode.parentNode.offsetLeft) - $(n).width();
		var y = (evt.pageY - n.parentNode.parentNode.parentNode.offsetTop) -204;
		coords.x = x;
		coords.y = y;
	}
	
	//showAnswer function
	function showAnswer(evt){
		mousePos(evt, this);
		$(this).parent('dl').children('dd').css({
				display : "none",
				marginTop : 0
			});
		$(this).next().css({
			"opacity" : 0,
			"display": "block" 
		}).animate({
			opacity: 1,
			marginTop: -$(this).height(),
			display: 'block'
		});
		return false;
	}

	function killdd(evt){
		$(this).parent('dl').children('dd').hide();
	}
	// functions for the about page.
	function openChild(evt){
		var n = $(this);
		var div = $(this).next('div');
		if(div.css('display') == 'block'){
			//item is open
			n.parent().children('div').slideUp(300);
		}else{
			n.parent().children('div').slideUp(300);
			n.next().slideDown(300);
		}
	}
	// fire image replace on the menu items
	$("#mainmenu a").each(function(){imageReplace($(this), 48);});
	
	//insert q before each question.
	$("#questionbox dt p").each(function(){
		$(this).prepend("<img src='/images/icon-q.gif' /> ");
	});
//	$("#questionbox dt").each(function(){
//		$(this).bind('click', showAnswer).css("cursor", "pointer");
//	});
//	$("#questionbox dd").each(function(){
//		$(this).bind('click', killdd);
//	});
	//about menus
	$("#inner h3").each(function(){
		$(this).bind("click", openChild);
	});
	
	$(function(){$('#questionholder').jScrollPane();});
	
	$('label').labelOver('over-apply');
	
	// rotation
	var imagecount = 0;
	var count = 0;
	
	function rotateblocks(n, p){
		var delay = p;
		var total = 0;
		
		n.find("a").each(function(i){
			 	if(i != 0) $(this).hide();
				$(this).addClass("blockitem" + i);
				total++;
		});
		imagecount = total - 1;
		setInterval(doLoop, delay);
	}
	
	function doLoop(){
		var max = imagecount;
		if(count == 0){
			$(".blockitem" + max).fadeOut(300);
		}
		$(".blockitem" + (count-1)).fadeOut(300);
		$(".blockitem" + count).fadeIn(300);
		if(max == count) {
			count = 0;
		}else{
			count++;
		}
	};
	
	rotateblocks($("#tickercontent"), 7000);
	
});
