﻿// JScript File
var objImages = {
"currentPage" : 0,
"currentImage":0,
"totalPages":0,
"pageSize":0,
"rowSize":0,
"imageForder": "",
"images" :[] ,
		   
	init : function(arrayAsJSONText, imgFolder, pageSize, rowSize , noThumbs) {
		this.images=eval(arrayAsJSONText) ;	
	
		this.imageFolder = imgFolder;
		this.pageSize= pageSize;
		this.rowSize= rowSize
		if (this.images.length % this.pageSize == 0 )
		this.totalPages = Math.floor(this.images.length /this.pageSize);
		else
		
		this.totalPages = Math.floor(this.images.length /this.pageSize)+1;
		this.currentPage=0;
		this.currentImage=0;
		var startNdx= this.currentPage * this.pageSize;	
	
		if (!noThumbs) 
		{ 
	
		this.displayImages (startNdx);
		}
	
		
	},
		   
	displayImages: function(startNdx){
		var str= "";
		var specialClass;
		var thumNailHolder = '<div class="thumbnail">';
		var div = window.document.getElementById('div_thumbImages');
		var endNdx = startNdx + this.pageSize;			
		if (endNdx >= this.images.length)
			endNdx = this.images.length;
		for (i = startNdx; i < endNdx; i ++){
		if ((i+1) % this.rowSize == 0)
		{specialClass="class=\"last\"";
		}
		
		else {specialClass="";}
		
			str= str +thumNailHolder+"<img " + 	specialClass + " src=\""+ this.imageFolder + this.images[i].small+ "\" onclick=\"javascript:Effect.Combo('slider_content', '"+this.imageFolder + this.images[i].large+ "\', " + i + ")\" /></div>";
		}
		div.innerHTML=str; 
		this.setLargeImage(0);
	},
		   

		  
	setLargeImage:function(imageId){
		if (imageId != null)
		this.currentImage= imageId;
		img = this.images[this.currentImage];
		$('div_img').src=this.imageFolder + img.large;	
		if (img.maps != null && img.maps.length >0 && $('map') != null){
	
			$('div_img').useMap="#map"+imageId;
			var outputString= "<map name=\"map"+imageId+"\">";
		  	for (i = 0; i < img.maps.length; i ++){
		  		if (img.maps[i].coords !=""){
					outputString += "<area shape=\"" + img.maps[i].shape + "\"";
	        		outputString += " coords=\"" + img.maps[i].coords + "\"";
	        		switch (img.maps[i].sellStatus)
	        		{
	        		case "available":	        		
						
						outputString += " onmouseover=\"ddrivetip(tipImg+'Click for Detail');\"";
	        			
	        			outputString += " href=\"javascript:getProductContent('"+img.maps[i].prodId+"')\"";
	        		break;
	        		case "notAvailable":
	        		case "sold out":
						outputString += " onmouseover=\"ddrivetip('So Hot, It\\&#39;s Sold Out',null,110);\"";
	        			outputString += " href=\"#\"";	        			
	        			outputString += " onclick=\"return false;\"";
	        		break;
	        		case "coming soon":
							outputString += " onmouseover=\"ddrivetip('Not Available','white',70);\"";
						
	        			outputString += " href=\"#\"";	        			
	        			outputString += " onclick=\"return false;\"";
	 				break;
	 				}//close switch
	 				outputString += " onmouseout=\"hideddrivetip();\" />";;
	 			//outputString += "  />";;
        		}
			}
			outputString += "</map>";
			//alert (outputString);
			$('map').update(outputString);
		}
		//MAKE HITBOX PAGE CALL
	// commented out for now ALINA5/14	hbx(0);
	},
		   
	getCurrentProducts: function(){
		return this.images[this.currentImage].products;
	},
	
	getCurrentImage :function (){
		return this.imageFolder + this.images[this.currentImage].large;
	},
		   
	navigateImage: function (theImage){
		var newCurrentImage = this.currentImage + eval(theImage);
		if (newCurrentImage < 0)
		   	newCurrentImage = this.images.length-1;
		if (newCurrentImage >= this.images.length)
		   	newCurrentImage= 0;
		this.setLargeImage(newCurrentImage, true);
	},
		   
	page: function(thePage){
		this.currentPage = this.currentPage + eval(thePage)
		if (this.currentPage < 0)
		   this.currentPage = this.totalPages-1;
		if (this.currentPage >= this.totalPages)
		   this.currentPage= 0;
		var startNdx = this.currentPage * this.pageSize;
		this.displayImages(startNdx);
	},
		   
	show :function (x){
		$('status').update(x);
	}
}



