
var hotproductpage = 0;
var hotproductcount = 1;
var stopchangehotproduct = 0;

function prehotproduct() {
	//alert("pre");
	hotproductpage--;
	if(hotproductpage < 0) {
		hotproductpage = 0;
	}
	//window.status = "" + hotproductpage;
	showProductImage();
}



function nexthotproduct() {
	//alert("next");
	hotproductpage++;
	if(hotproductpage > 10) {
		hotproductpage = 10;
	}
	//window.status = "" + hotproductpage;
	showProductImage();
}

function showProductImage() {
	var contextpath = dwr.util.getValue("id_contextpath");
	
	BeanHandler.getHotProducts(7, hotproductpage, hotproductcount, function(gifts) {
		var i = 0;
		if(gifts == null) {
			hotproductpage --;
			if(hotproductpage < 0) {
				hotproductpage = 0;
			}
		}
		if(gifts != null) {
			//for(i = 0; i <gifts.length; i++ ) {
				//alert("" + 0 );
				var gift = gifts[0];
				var imglist = document.getElementById("id_hotproduct");
				var detailURL= contextpath + "/ViewGiftDetail.jsp?giftId=" + gift.giftID;
				var imageURL = contextpath + "/images/" + gift.imagePath;
				var giftName = gift.giftName;
				var price = gift.price;
				if(imglist != null) {
					imglist.innerHTML = ''
					//'<div class="hotgift_img">'
						+ '<a href="' + detailURL + '"> '
							+ '<img src="' + imageURL + '" />'
						+ '</a>'
						+ '<div class="name">'
							+ giftName
						+ '</div>'
						+ '<div class="price">'
							+ 'S$&nbsp;' + price
						+ '</div>';
					//+ '</div>'
				
					//+ '<div class="cleaner">&nbsp;</div>';
				}
			//}
		}
		//window.status = "8000 -> " + page;
	});

}

function loadProductImage() {
	if(stopchangehotproduct == 0) {
		var contextpath = dwr.util.getValue("id_contextpath");
		
		BeanHandler.getHotProducts(7, hotproductpage, hotproductcount, function(gifts) {
			if(gifts != null && gifts.length == hotproductcount) {
				hotproductpage++;
				if(hotproductpage > 10) {
					hotproductpage = 0;
				}
			}
			else {
				hotproductpage = 0;
			}
			//alert("" + hotproductcount + " " + hotproductpage);
			var i = 0;
			if(gifts != null) {
				//for(i = 0; i <gifts.length; i++ ) {
					//alert("" + 0 );
					var gift = gifts[0];
					var imglist = document.getElementById("id_hotproduct");
					var detailURL= contextpath + "/ViewGiftDetail.jsp?giftId=" + gift.giftID;
					var imageURL = contextpath + "/images/" + gift.imagePath;
					var giftName = gift.giftName;
					var price = gift.price;
					if(imglist != null) {
						imglist.innerHTML = ''
						//'<div class="hotgift_img">'
							+ '<a href="' + detailURL + '"> '
								+ '<img src="' + imageURL + '" />'
							+ '</a>'
							+ '<div class="name">'
								+ giftName
							+ '</div>'
							+ '<div class="price">'
								+ 'S$&nbsp;' + price
							+ '</div>';
						//+ '</div>'
					
						//+ '<div class="cleaner">&nbsp;</div>';
					}
				//}
			}
			window.setTimeout("loadProductImage()", 5000);
			//window.status = "8000 -> " + page;
		});
	}
	else {
		window.setTimeout("loadProductImage()", 1000);
		//window.status = "1000 -> " + page;
	}
}


function attachOnloadEvent(func, obj) {
	if(typeof window.addEventListener != 'undefined') {
		window.addEventListener('load', func, false);
	} 
	else if (typeof document.addEventListener != 'undefined') {
		document.addEventListener('load', func, false);
	} 
	else if (typeof window.attachEvent != 'undefined') {
		window.attachEvent('onload', func);
	} 
	else {
		if (typeof window.onload == 'function') {
			var oldonload = onload;
			window.onload = function() {
				oldonload();
				func();
			};
		} else {
			window.onload = func;
		}
	}
}


//attachOnloadEvent(loadProductImage, window);

