if (document.images) {
	mainImage1 = new Image(990,266);
	mainImage1.src = "images/home_banner_01.jpg";
	mainImage2 = new Image(990,266);
	mainImage2.src = "images/home_banner_02.jpg";
	mainImage3 = new Image(990,266);
	mainImage3.src = "images/home_banner_03.jpg";
	mainImage4 = new Image(990,266);
	mainImage4.src = "images/home_banner_04.jpg";
	mainImage5 = new Image(990,266);
	mainImage5.src = "images/home_banner_05.jpg";
	mainImage6 = new Image(990,266);
	mainImage6.src = "images/home_banner_06.jpg";
	mainImage7 = new Image(990,266);
	mainImage7.src = "images/home_banner_07.jpg";
	mainImage8 = new Image(990,266);
	mainImage8.src = "images/home_banner_08.jpg";
	mainImage9 = new Image(990,266);
	mainImage9.src = "images/home_banner_09.jpg";
	mainImage10 = new Image(990,266);
	mainImage10.src = "images/home_banner_09.jpg";	
}
function swapImage(id) {
	$(id).attr("src",mainImages[imageKey]);
	$("#banner1, #banner2").click(function() {
		gtfo(links[linkKey-1]);
	});
}
function crossfade(id) {
	if(id != "bannerNext"){
	   id = "bannerLast";
	   if (imageKey == 0) {
			var lastkey =  mainImages.length-2;
			var nextkey = imageKey;
			imageKey = mainImages.length-1;			
	   }else{
			var lastkey =  imageKey-2;
			var nextkey = imageKey;		   
			imageKey = imageKey-1;
	   }
	   $("#bannerNext").animate({opacity:0},0);
	}else{
	   if (imageKey == mainImages.length-1) {
			var lastkey =  imageKey;
			var nextkey = 1;
			imageKey = 0;
	   }else{
		   var lastkey =  imageKey;
		    if(imageKey == mainImages.length-2){
				var nextkey = 0;
			}else{
				var nextkey = imageKey+2;
			}			
			 
			imageKey = imageKey+1;
	   }
	}
	//--------------------------------------------------------------
	$("#bannerNow").animate({opacity:0},2000,"swing",function () {
		$('#bannerNow').attr("src",mainImages[imageKey]);
		$('#bannerNext').attr("src",mainImages[nextkey]);
		$('#bannerLast').attr("src",mainImages[lastkey]);
	});
	$("#bannerNow").animate({opacity:1},0,"swing",function () {
		$("#bannerLast").animate({opacity:1},0);
		$("#bannerNext").animate({opacity:1},0);
		control = window.setTimeout('crossfade("bannerNext");',4500);
	});
}

$(document).ready(function(){
	bClick();
	control = window.setTimeout('crossfade("bannerNext");',4500);
		$("#banner1, #banner2").click(function() {
		gtfo('<?= $linkHref ?>');
	});
	$('#home-bannerIndex').hover(function() {},
	function() {
		var ban3 = $('img#banner3');
		var ban4 = $('img#banner4');
		if(ban3.css('display') != 'none') {
			ban4.hide();
			ban3.fadeOut();	
		};
	});
	setTimeout("changeMessage(0)", 2000);
	
});

function bClick(){
	$('.arrow_button').click(function(){
	clearTimeout(control);
	$("#bannerNow").animate({opacity:1},0);
		var id = $(this).attr('id');
	  if(id != "bannerNext"){
	   id = "bannerLast";
	   if (imageKey == 0) {
			var lastkey =  mainImages.length-2;
			var nextkey = imageKey;
			imageKey = mainImages.length-1;			
	   }else{
			var lastkey =  imageKey-2;
			var nextkey = imageKey;		   
			imageKey = imageKey-1;
	   }
	   $("#bannerNext").animate({opacity:0},0);
	}else{
	   if (imageKey == mainImages.length-1) {
			var lastkey =  imageKey;
			var nextkey = 1;
			imageKey = 0;
	   }else{
		   var lastkey =  imageKey;
		    if(imageKey == mainImages.length-2){
				var nextkey = 0;
			}else{
				var nextkey = imageKey+2;
			}			
			 
			imageKey = imageKey+1;
	   }
	}
	
	$("#bannerNow").animate({opacity:0},0,"swing",function () {
		$('#bannerNow').attr("src",mainImages[imageKey]);
		$('#bannerNext').attr("src",mainImages[nextkey]);
		$('#bannerLast').attr("src",mainImages[lastkey]);
	});
	$("#bannerNow").animate({opacity:1},0,"swing",function () {
		$("#bannerLast").animate({opacity:1},0);
		$("#bannerNext").animate({opacity:1},0);
		control = window.setTimeout('crossfade("bannerNext");',4500);
	});
	});
}

displayMessages = new Array('mess0','mess1','mess2','mess3','mess4','mess5','mess6', 'mess7', 'mess8', 'mess9', 'mess10', 'mess11', 'mess12', 'mess13');
function changeMessage(id) {
	var next = id+1;
	if(next >= (displayMessages.length)) {
		next = 0;
	}
	$('#messages').find('#mess'+id).fadeOut('slow');
	$('#messages').find('#mess'+next).fadeIn('slow');
	id++;
	setTimeout("changeMessage("+next+")", 2500);
}
