var currentIpix = 0;
var currentPhoto = 0;
function switchRoom(index){
  currentIpix = index;
  currentPhoto = index;
  switchView(true);
  //imgSwap('mousedown',index);
}
function imgSwap(evt,node) {
 if(evt == "mousedown"){
  
  var imgClass = "room";
  
  var coords = document.getElementById("room").childNodes[node].coords.split(",");
   
  var action = "mousedown";
 }else{
  evt = (evt) ? evt : event;
  var elem = (evt.target) ? evt.target : evt.srcElement;
  var imgClass = elem.parentNode.name;
  var coords = elem.coords.split(",");
  var action = evt.type;
 }
 
 var clipVal = "rect(" + coords[1] + "px " +
       coords[2] + "px " +
       coords[3] + "px " +
       coords[0] + "px)";
 var imgStyle;
 evt.cancelBubble = true;
 return false;
}

function switchView(noSwitch){
 var targetBlock = document.getElementById('pic_viewer_img');
 targetBlock.innerHTML = '';
 var htmlReplaceBlock = '';
 if (navigator.appVersion.toLowerCase().indexOf("mac")!=-1){
  //do nothing if it's a mac
 }else{
  if(currentView=='ipix' && noSwitch){
     
   currentView = 'ipix';  
   
   // set a variable to store the file type of the file
   var fileType = ipixList[currentIpix];  
   // cut down the variable to only the file type
   fileType = fileType.substring(fileType.indexOf('.')+1);
   
   // if user has used a jpeg then use this java class to create ipix
   if((fileType=='jpg') || (fileType=='jpeg')){
  
    htmlReplaceBlock = '<applet code="ptviewer.class" archive="' + JAR + '" width="324" height="192">';
    htmlReplaceBlock += '<param name=file value="'+ipixList[currentIpix]+'">';
    htmlReplaceBlock += '<param name=cursor value="MOVE">';
    htmlReplaceBlock += '<param name=pan value=-105><param name=showToolbar value="true">';
    htmlReplaceBlock += '<param name=fov value="105"><param name=fovmin value="50"><param name=fovmax value="105">';
    htmlReplaceBlock += '<param name="auto" value="0.04"><param name=imgLoadFeedback value="true">';
    htmlReplaceBlock += '</applet>';
   }
   // if the file type is an ipix file then use this java class
   else if((fileType=='ipx') || (fileType=='ipix')){
    htmlReplaceBlock = '<applet name="IpixViewer" code="IpixViewer.class" archive="IpixViewer.jar" width="324" height="192">';
    htmlReplaceBlock += '<param name="url" value="media/ipix/'+ipixList[currentIpix]+'">';
    htmlReplaceBlock += '<param name="toolbar" value="on"><param name="initfov" value="0"><param name="SpinSpeed" value="-4"><param name="SpinStyle" value="flat">';
    htmlReplaceBlock += '</applet>';
   }
   
   targetBlock.innerHTML = htmlReplaceBlock;
   
   
  }else if(currentView=='ipix'){ 
  
   currentView = 'photo';
   
   document.getElementById('pic_viewer_img').innerHTML = '<img src="'+photoList[currentPhoto]+'" width="324" height="192" alt="" border="0">';
   
  }else{ 
   
   currentView = 'ipix';
   
   // set a variable to store the file type of the file
   var fileType = ipixList[currentIpix];  
   // cut down the variable to only the file type
   fileType = fileType.substring(fileType.indexOf('.')+1);
   
   
   // if user has used a jpeg then use this java class to create ipix
   if(fileType=='jpg' || fileType=='jpeg'){  
    htmlReplaceBlock = '<applet code="ptviewer.class" archive="' + JAR + '" width="324" height="192">';
    htmlReplaceBlock += '<param name=file value="'+ipixList[currentIpix]+'">';
    htmlReplaceBlock += '<param name=cursor value="MOVE">';
    htmlReplaceBlock += '<param name=pan value=-105><param name=showToolbar value="true">';
    htmlReplaceBlock += '<param name=fov value="105"><param name=fovmin value="50"><param name=fovmax value="105">';
    htmlReplaceBlock += '<param name="auto" value="0.04"><param name=imgLoadFeedback value="true">';
    htmlReplaceBlock += '</applet>';
   }
   // if the file type is an ipix file then use this java class
   else if((fileType=='ipx') || (fileType=='ipix')){
    htmlReplaceBlock = '<applet name="IpixViewer" code="IpixViewer.class" archive="IpixViewer.jar" width="324" height="192">';
    htmlReplaceBlock += '<param name="url" value="media/ipix/'+ipixList[currentIpix]+'">';
    htmlReplaceBlock += '<param name="toolbar" value="on"><param name="initfov" value="0"><param name="SpinSpeed" value="-4"><param name="SpinStyle" value="flat">';
    htmlReplaceBlock += '</applet>';
   }
   targetBlock.innerHTML = htmlReplaceBlock;
   
  }
 }
}
