/**
* This function makes the home page image rotate.
*  The div  has an id of hp-main-image
*  All the images are in  the same directory as the initial one that has been 
*  hard-coded into the div. (/components/com_virtuemart/shop_image/homepage/)
*  All the imges are called slide0.jpg to slide4.jpg
**/
////////////////////////////////////////////////////////////
var fades = 20;     //the number of times that the image changes
var t;
 
function fader() {
	fades--;
 
	if (fades == 0) {
		clearTimeout(t);
	}
 
	max = 5;
	
	j = jQuery("#hp-main-image img").attr('src').split('slide');
	k = j[1].split('.jpg');
	u = j[0] + "slide"; //partial url of the image
	
	cur_image = parseInt(k[0]);
 
	next_image = (cur_image+1) % max;
	
	// set div bg to img src
	jQuery("#hp-main-image").css('background-image', 'url('+ u + cur_image + '.jpg)');
	
	// set img to display none
	jQuery("#hp-main-image img").css({opacity: 0});
 
	jQuery("#hp-main-image img").attr("src", u + next_image + ".jpg");
 
	jQuery("#hp-main-image img").animate( {opacity: 1}, 1500);
}

jQuery(document).ready(function() {
	t = setInterval("fader()", 3000);
});

