
$(document).ready(
	function(){
		jQuery.preLoadImages("_img/top/main-img_01.jpg", "_img/top/main-img_02.jpg", "_img/top/main-img_03.jpg", "_img/top/main-catchcopy_01-trans.png", "_img/top/main-catchcopy_02-trans.png", "_img/top/main-catchcopy_03-trans.png");
		$(".bgimage").fadeOut(0);
		$(".catchcopy").fadeOut(0);
		resizer();
		window.onresize = resizer;
		imageSlider();
	}
);

function resizer(){
	xscale = (document.documentElement.clientWidth - 230)/1701;
	yscale = document.documentElement.clientHeight/1134;
	fixscale = Math.max(xscale, yscale);
	fixWidth = Math.ceil(1701*fixscale);
	$(".bgimage").width(fixWidth);
	$(".bgimage").css("left", ((document.documentElement.clientWidth - 230) / 2) - ($(".bgimage").width() / 2) + 230 + "px");
	$(".catchcopy").css("left", ((document.documentElement.clientWidth - 230) / 2) + 230 - 71 + "px");
	if(document.documentElement.clientHeight < 595){
		$(".catchcopy").css("top", (595 / 2) - 300 + "px");
	} else {
		$(".catchcopy").css("top", (document.documentElement.clientHeight / 2) - 300 + "px");
	}
	
	if(document.documentElement.clientHeight < 595){
		$("#copyright").css("bottom", "auto");
		$("#copyright").css("top", "550px");
	} else {
		$("#copyright").css("top", "auto");
		$("#copyright").css("bottom", "15px");
	}
}

mainImages = new Array(3);
mainImages[0] = "_img/top/main-img_01.jpg";
mainImages[1] = "_img/top/main-img_02.jpg";
mainImages[2] = "_img/top/main-img_03.jpg";
catchCopies = new Array(3);
catchCopies[0] = "_img/top/main-catchcopy_01-trans.png";
catchCopies[1] = "_img/top/main-catchcopy_02-trans.png";
catchCopies[2] = "_img/top/main-catchcopy_03-trans.png";
var i = 0;
var j = 1;
var interval = 7500;
var delay    = 500;
var fadetime = 2500;

function imageSlider(){
	var fadein = setTimeout(function (){
		$("#bgimage_f").fadeIn(fadetime);
	}, 0);
	var fadein = setTimeout(function (){
		$("#bgimage_b").attr('src', mainImages[i]);
		$("#bgimage_b").fadeIn(0);
		$("#catchcopy").fadeIn(0);
		$("#catchcopy").attr('src', catchCopies[i]); 
	}, fadetime);
	var fadeout = setTimeout(function (){
		$("#bgimage_f").fadeOut(fadetime);
	}, fadetime + delay);
	var chgURL = setTimeout(function (){
		i += 1;
		if(i == 3) i = 0;
		$("#bgimage_f").attr('src', mainImages[i]); 
	}, fadetime*2 + delay + interval);

	var repeat = setTimeout(imageSlider, fadetime*2 + delay + interval);
}

(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)


