var count = 0;
var preface = "background";   

$centerWrapper = function() {
	 if($(window).width()>950) {
 	  $("#wrapper").css("left",Math.round(($(window).width()-950)/2)+"px")
	  $("#wrapper_top_center").css("left",Math.round(($(window).width()-950)/2)+"px")
   } else {
	  $("#wrapper").css("left","0px");
	  $("#wrapper_top_center").css("left","0px");
   }
}
function equalHeight(group) {
   tallest = 0;
   group.each(function() {
      thisHeight = $(this).height();
      if(thisHeight > tallest) {
         tallest = thisHeight;
      }
   });
   group.height(tallest);
}
$wrapperheight = function() {
	//$("#background_holder").height($(window).height());
}
$.fn.preload = function() {
    this.each(function(){
        $('<img/>')[0].src = this;
    });
}
$(document).ready(function() {
   $("#next2").click(
	   function() {
			$("#background_holder").fadeOut('120', function() {
				$("#background_holder").removeClass(preface+count);
				count++;
				if(count == maxcount) {count = 0;}
				$("#background_holder").addClass(preface+count);
				$("#background_holder").delay(200).fadeIn('800');
			});	   	 	
		}
   );
   $("#previous").click(
		function (){
			$("#background_holder").fadeOut('120', function() {
				$("#background_holder").removeClass(preface+count);
				if(count == 0) {count = maxcount -1; } else {count = count - 1; }
				$("#background_holder").addClass(preface+count);
				$("#background_holder").delay(200).fadeIn('800');
			});	   	 	
		}
   );
   window.setInterval(timed_next, 6000);
   function timed_next() {
		$("#background_holder").fadeOut('120', function() {
			$("#background_holder").removeClass(preface+count);
			count++;
			if(count == maxcount) {count = 0;}
			$("#background_holder").addClass(preface+count);
			$("#background_holder").delay(200).fadeIn('800');
		});	   	 	
	}
   
   
   $wrapperheight();
   $centerWrapper();
   $(window).resize(function() {
	   $centerWrapper();
       $wrapperheight();
   });
   $("#footer img").each(function () {$(this).fadeTo('slow', 0.4);});
   $("#footer img").each(
   		function () {
		   $(this).hover(
				function() {
					$(this).fadeTo('fast', 1);
				}
			)
		}
	);
});
