var ProductAtom_Images = new Array();
var ProductAtom_ImgCount = -1;

var _ProductImage_Url, _ProductImage_Width, _ProductImage_Height, _ProductImage_Alt;
function ProductAtom_Image(productid, url, width, height, alt, ImgId){
	_ProductId = productid;
	_ProductImage_Url = url;
	_ProductImage_Width = width;
	_ProductImage_Height = height;
	_ProductImage_Alt = alt;
	_ProductImgId = ImgId;
	this.ProductId = productid;
	this.Url = _ProductImage_Url
	this.Width = _ProductImage_Width;
	this.Height = _ProductImage_Height;
	this.Alt = _ProductImage_Alt;
	this.ImgId = _ProductImgId;
}

function ProductAtom_ViewImage(productid, img){
	var imgid = parseInt(img.getAttribute("ImageId"));
	var img = ProductAtom_GetImage(productid, imgid);
	window.open(img.Url);
}
function ProductAtom_GetImageCount(){
	try{
		var count = ProductAtom_Images.length;
		if(count == undefined){count = 0;}
		return count;
		
	}catch(ex){}
}
function ProductAtom_GetImage(productid, imgid){
	for(var i = 0; i < ProductAtom_Images.length; i++){
		if(ProductAtom_Images[i].ProductId == productid && ProductAtom_Images[i].ImgId == imgid){
			return ProductAtom_Images[i];
		}
	}
}

function ProductAtom_InitImg(productid, imagecount){
	document.getElementById("ProductAtom_TotalImages" + productid).innerHTML = imagecount;
	ProductAtom_NextImg(productid,-1);
	
}
function ProductAtom_NextImg(productid, imgid){
	try{
	
		ImgCount = parseInt(document.getElementById("ProductAtom_CurrentImage"+productid).innerHTML)-1;	
		TotalImgCount = parseInt(document.getElementById("ProductAtom_TotalImages"+productid).innerHTML);
		
		if(imgid != -1){ImgCount += 1;}else{ImgCount = 0;}
			
		if(ImgCount >= (TotalImgCount)){ImgCount = 0;}
		
		var img = document.getElementById("ProductImg"+productid);
		var image = ProductAtom_GetImage(productid, ImgCount);
		img.ProductId = productid;
		img.src = image.Url;
		img.width = image.Width;
		img.height = image.Height;
		img.alt = image.Alt;
		img.setAttribute("ImageId", image.ImgId);

		document.getElementById("ProductAtom_CurrentImage"+productid).innerHTML = ImgCount+1;	

	}catch(ex){ }
}



