$(document).ready(function(){
	
	// initilize form elements
	
	if ($("form") && $("form") !== null) {
	
  	$("form input[autoclear]").each(function(i) {
  		if (this.value == $(this).attr("autoclear")) {
  			$(this).addClass("empty");
  		}
  	}).focus(function() {
  		if ($(this).data("val") == undefined) { // first call
  			if ($(this).attr("autoclear")) {
  				// store the given original
  				$(this).data("val", $(this).attr("autoclear"));
  			} else {
  				// use whats there as original
  				$(this).data("val", this.value);
  			}
  		}
  		if (this.value == $(this).data("val")) { // clear field
  			this.value = '';
  			$(this).removeClass("empty");
  		}
  	}).blur( function() {
  		if (this.value == '') {
  			$(this).addClass("empty");
  			this.value = $(this).data("val");
  		}
  	});
  	
  	$("form input[verify=true]").click(function(e) {
  		$formid = $(this).parents("form:first").attr("id");
  		
  		if ($("#" + $formid + " input[required=true]").hasClass("empty")) {
  			alert("Please fill in required fields denoted by *.");
  			return false;
  		}
  		
  		$("#" + $formid + " input[autoclear]").each(function(i) {
  			if ($(this).hasClass("empty")) {
  				this.value = "";
  			}
  		});
  	});
  
  }
  
  if ($('a[href=#') && $('a[href=#') !== null) {
  
  	$('a[href*=#]').click(function() {
  		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
  			var $target = $(this.hash);
  			$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
  			if ($target.length) {
  				var targetOffset = $target.offset().top;
  				if (targetOffset == 0) {
  					// found nothing or refering to top of page, ignore
  					return false;
  				}
  				$('html,body').animate({scrollTop: targetOffset - 10}, 1000);
  				
  				pageTracker._trackEvent('Anchor', 'Scroll', location.pathname, this.hash);
  				return false;
  			}
  		}
  	});

  }
  
  
  if ($("#issuecover") && $("#issuecover") !== null) {
  
  	$("#issuecover").hover(
  		function(e){
  		$("#issuecoverhover").fadeIn(100);
  		},
  		function(e){
  		$("#issuecoverhover").fadeOut(100);
  		}
  	);
  	
  	$("#issuecoverfooter").hover(
  		function(e){
  		$("#issuecoverfooterhover").fadeIn(100);
  		},
  		function(e){
  		$("#issuecoverfooterhover").fadeOut(100);
  		}
  	);
	
	}

	// lightbox initialization
	$(function() {
	//$('a[@rel*=lightbox]').lightBox(); // Select all links that contains lightbox in the attribute rel
	//$('.gallery a').lightBox(); // Select all links in object with gallery ID
	//$('a.lightbox').lightBox(); // Select all links with lightbox class
	//$('a').lightBox(); // Select all links in the page
	});
	
	if ($(".footeryear") && $(".footeryear") !== null) {
	
  	$(".footeryear .archiveprev").click(function() {
  		changefooteryear(-1, $(this));
  	});
  	
  	$(".footeryear .archivenext").click(function() {
  		changefooteryear(1, $(this));
  	});
  	
  	function changefooteryear($yearoffset, $obj) {
  		$year = parseInt($obj.parent().attr("year"));
  		
  		$yearelem = $("#footeryear-" + ($year + $yearoffset));
  		$yeararchiveelem = $("#footerarchive-" + ($year + $yearoffset));
  
  		if ($yearelem.size() != 0 && $yeararchiveelem.size() != 0) {
  			$obj.parent().hide();
  			$yearelem.show();
  			$("#footerarchive-" + $year).hide();
  			$yeararchiveelem.show();
  		}
  	}

    
  
  	/*
  	$(window).scroll(function() {
  		if($("#navibar").offset().top < $(this).scrollTop()) {
  			//alert("a");
  			//$('#navibar ul').css('position', "fixed");
  			$('#navibar ul').css('position', "fixed");
  		} else {
  			//alert($(this).scrollTop());	
  			$('#navibar ul').css('position', "relative");
  		}
  	});
  	*/
  	
  	$(window).scroll(function() {
  		$navibar = $("#navibar");
  		$navibarul = $('#navibar ul');
  		//$navibarul.stop();
  		
  		if($navibar.offset().top > $(this).scrollTop()) {
  			//$navibarul.animate({top: "0px"}, "10");
  			$navibarul.css('top', '0px');
  		} else {
  			$val = $(this).scrollTop() - $navibar.offset().top;
  			//$navibarul.animate({top: parseInt($val) + "px"}, "10");
  			$navibarul.css('top', parseInt($val) + "px");
  		}
  	});
  
  } // end if if ($(".footeryear") && $(".footeryear") !== null)
  
}); 
