$(document).ready(function() {
  if (!document.getElementsByTagName) return;
  var anchors = document.getElementsByTagName("a");
  for (var i=0; i<anchors.length; i++) {
    var anchor = anchors[i];
    if (anchor.getAttribute("href") &&
      anchor.getAttribute("rel") == "external")
      anchor.target = "_blank";
  }
	
	var imageInterval = 3000;
	var count = 1;
	var intervalID = setInterval(function(){
	    nextImage();
	},imageInterval);
	
	var archiveHeight;
	archiveHeight = $('#archives-2 ul').height();
	$('#archives-2 ul').css('height','200px');
	
	$('.buttons li').click(function(){
		count = $(this).html();
		$('.buttons li').removeClass('active');
		$(this).addClass('active');
		$('#headerimg').scrollTo('li:eq('+(count-1)+')', 600, {axis:'x'} );
		clearInterval(intervalID);
		intervalID = setInterval(function(){
		    nextImage();
		},imageInterval);		
	})
	$('.see-all-archives').click(function(){
	  if ($(this).html()=='See All'){
	    $('#archives-2 ul').animate({height: archiveHeight}, 'medium');
  	  $(this).html('See Less');
	  }else{
	    $('#archives-2 ul').animate({height: '200px'}, 'medium');
  	  $(this).html('See All');
	    
	  }

	})
	
	function nextImage(){
		count++;
		if (count > $('.buttons li').length) count = 1;
		$('#headerimg').scrollTo('li:eq('+(count-1)+')', 600, {axis:'x'} );
		$('.buttons li').removeClass('active');
		$('.buttons li:eq('+(count-1)+')').addClass('active');
	}

	$('#headerimg').hover(function(){
		clearInterval(intervalID);
	},function(){
		intervalID = setInterval(function(){
		    nextImage();
		},imageInterval);
	})
	
})
