function get(s){
   return document.getElementById(s);
}
var imgPreloader = new Image();
var images = new Array();
var imgTag = {};
function mm360Viewer(strViewId, strPrefix, strImageFolder, nImageCount) {
  var i = 0;
  imgTag = get(strViewId);
  
  for(i = 0; i < nImageCount; i++){
  	var imgSrc = strImageFolder + "/" + strPrefix + String(i+1) + ".gif";
	imgPreloader.src=imgSrc;
  	images[i] = imgSrc;
  }
  
  get(strViewId).onmousemove = function(e){
     var x = 0;
     if(window.event){
	    x = Math.round(((window.event.clientX - filmstrip.offsetLeft) / 300 *25));
	 }else if(e.clientX){
	    x = Math.round(((e.clientX - e.target.offsetLeft) / 300 * 25));
	 }	
	if(x >= images.length)
	  x = images.length - 1;
	
	imgTag.src = images[x];  
  };
  
  imgTag.src = images[0];
}

var filmstrip = {};

function mm360Filmstrip(divId, frames, width, filmstrip_img){
   filmstrip = get(divId);
	 filmstrip.style.backgroundImage = filmstrip_img;
   var filmPosX = findPosition(filmstrip)[0];
   filmstrip.onmousemove = function(e){
     var x = 0;
     if(window.event){
	    x = Math.round(((window.event.clientX - filmPosX) / width * frames));
	 }else if(e.clientX){
	    x = Math.round(((e.clientX - filmPosX) / width * frames));
	 }
	 if(x >= frames)
	  x = frames - 1;

	 var bgpos = String((-1 * width * x)) + "px";
	 filmstrip.style.backgroundPosition = String((-1 * width * x ))+ "px";
   }
	 
	 this.showView = function(obj){
	 		
	 }
}


function MM360FilmstripViewer (_strDivId, _frames, _width, _filmstrip){
   this.id = _strDivId;
   get(_strDivId).frames = _frames;
	 get(_strDivId).style.width = _width + "px";
	 get(_strDivId).nWidth = _width;
	 get(_strDivId).style.backgroundImage = 'url('+_filmstrip+')';
	 get(_strDivId).style.width = _width + "px";
	 get(_strDivId).style.backgroundPosition = "0px";
	 get(_strDivId).filmPosX = findPosition(get(_strDivId))[0];
	 get(_strDivId).onmousemove = function(e) {
	   var x = 0;
     if(window.event){
	    x = Math.round(((window.event.clientX - this.filmPosX) / this.nWidth * this.frames));
	   }else if(e.clientX){
	    x = Math.round(((e.clientX - this.filmPosX) / this.nWidth * this.frames));
	   }
		 if(x >= this.frames)
		   x = this.frames - 1;
		 
	   var bgpos = String((-1 * this.nWidth * x)) + "px";
		 get(_strDivId).style.backgroundPosition = String((-1 * this.nWidth * x ))+ "px";
	 }
	 
	 this.showView = function(obj){
	   get(this.id).frames = obj.frames;
		 get(this.id).style.backgroundImage = 'url('+obj.image+')';
		 get(this.id).style.width = obj.width;
		 get(this.id).style.backgroundPosition = 0+"px";
	 }
}


function findPosition(obj){
  var curLeft = curTop = 0;
  if(obj.offsetParent){
    do{
	  curLeft += obj.offsetLeft;
	  curTop += obj.offsetTop;
    }while(obj = obj.offsetParent);
  }
  return [curLeft, curTop];
}