var im_array = new Array(
						 'templates/kingfisher/images/interest-free.jpg',
						 'templates/kingfisher/images/free-door.jpg'
						 );

var curr_id = 1;
var next_id = 2;
var swp_time = 10000;
var chg_speed = 2;
var curr_opacity = 100;

var len = im_array.length;
var num = Math.floor(Math.random() * (len - 1));
var pLoad = new Array()
var isOpera = (navigator.userAgent.indexOf('Opera')>=0) ? true : false;

function startShow() {
	if (document.images.h_image1)
	{
		document.images.h_image1.src=im_array[num++];
		for (i = 0; i < len; i++){
		   pLoad[i] = new Image();
		   pLoad[i].src = im_array[i];
		}
		showImage();			
	}
}

function showImage() {
	curr_opacity=100;

	document.getElementById('h_image'+curr_id).style.visibility = 'visible';
	if (isOpera) {
		document.getElementById('h_image'+curr_id).style.display = 'inline';
	}
	
	if (!isOpera) {
		document.getElementById('h_image'+next_id).style.visibility = 'visible';
	}
	
	if (document.all) {
		document.getElementById('h_image'+curr_id).style.filter = 'alpha(opacity=100)';
		document.getElementById('h_image'+next_id).style.filter = 'alpha(opacity=1)';
	}
	else {
		document.getElementById('h_image'+curr_id).style.opacity = 0.99;
		document.getElementById('h_image'+next_id).style.opacity = 0.01;
	}		
	
	document.getElementById('h_image'+next_id).src=pLoad[num++].src;

	if (num > (len-1)) {
		num=0;
	}
	setTimeout('swpImage()',swp_time);		
}

function swpImage() {

	curr_opacity--;

	if(document.all){
		document.getElementById('h_image'+curr_id).style.filter = 'alpha(opacity='+curr_opacity+')';
		document.getElementById('h_image'+next_id).style.filter = 'alpha(opacity='+(100-curr_opacity)+')';
	}
	else{
		document.getElementById('h_image'+curr_id).style.opacity = Math.max(0.01,curr_opacity/100);
		document.getElementById('h_image'+next_id).style.opacity = Math.min(0.99,(1 - (curr_opacity/100)));
	}

	if(curr_opacity>0){
		setTimeout('swpImage()',chg_speed);
	}
	else{
		document.getElementById('h_image'+curr_id).style.visibility = 'hidden';	
		if (isOpera) {
			document.getElementById('h_image'+curr_id).style.display = 'none';
		}
		if (curr_id==1) {
			curr_id = 2;
			next_id = 1;
		}
		else {
			curr_id = 1;
			next_id = 2;
		}
		showImage();
	}
}
