 if (top.location == self.location) {
    top.location.href ="index.html";
 }

 if (browserType != "old" && browserType != "NN5") {
     document.onmousedown = handleMouseDown;
     document.onmousemove = dragIt;
     document.onmouseup = releaseIt;
     document.onkeypress = checkKeyPress;
  }


  var output = ""

// BEGIN DRAG ROUTINES FOR NN4 AND IE4 ===================================

 //MOVE LAYER TO
 //This function simply changes the left and top coordinates of a layer
 //to the coordinates passed to it. This makes the layer move.

 function moveLayerTo(layerName,left,top) {

    if (browserType == "NN4") {
        eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.pageY=top');
        eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.pageX=left');
    }else if (browserType == "IE4"){
        eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.top=top');
        eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.left=left');
    }
 }
 

 var selectedObj, otherObj, offsetX, offsetY, offsetX1, offsetY1 = null;
 var swatches = 7;


 function handleMouseDown(evt) {

   setSelectedObj(evt);

   if (selectedObj) {

      if (selectedObj == "screen") {
         selectedObj = null;
         return false;
      }

      if (browserType == "NN4") {
         offsetX = evt.pageX - eval(layerRef+'["'+selectedObj+'"]'+styleSwitch+'.pageX');
         offsetY = evt.pageY - eval(layerRef+'["'+selectedObj+'"]'+styleSwitch+'.pageY');
      }else if (browserType == "IE4") {
         offsetX = window.event.offsetX;
         offsetY = window.event.offsetY;
      }

      // Get the offsets for the "other graphic" if there is one.
      // For the "Text handle" (movetext) it's the text layer itself.
      // For each swatch, it's the number image that identifies it.

      if (selectedObj == "movetext") {
         offsetX1 = offsetX;
         offsetY1 = offsetY - 15;
      }else if (selectedObj.substr(2,6) == "swatch") {
         offsetX1 = offsetX - 3;
         offsetY1 = offsetY - 3;
      }
   }
   return false;
 }


 function dragIt(evt) {

    if (selectedObj) {
       if (browserType == "NN4") {
          moveLayerTo(selectedObj,(evt.pageX - offsetX),(evt.pageY - offsetY));
       }else if (browserType == "IE4") {
          moveLayerTo(selectedObj,(window.event.clientX - offsetX),(window.event.clientY - offsetY));
       }

      // Move the "other graphic" if there is one.
      // For the "Text handle" (movetext) it's the text layer itself.
      // For each swatch, it's the number image that identifies it.

      otherObj = null;
      if (selectedObj == "movetext") {
         otherObj = "text";
      }else if (selectedObj.substr(2,6) == "swatch") {
         otherObj = "snum" + selectedObj.substr(8,1);
      }
      if (otherObj) {
         if (browserType == "NN4") {
            moveLayerTo(otherObj,(evt.pageX - offsetX1),(evt.pageY - offsetY1));
         }else if (browserType == "IE4") {
            moveLayerTo(otherObj,(window.event.clientX - offsetX1),(window.event.clientY - offsetY1));
         }
      }
 
    }
    return false;
 }


 function releaseIt(evt) {
     selectedObj = null;
     return false;
 }


 function setSelectedObj(evt) {

    // For Netscape, we have to figure out what was clicked by looking at
    // the boundaries of each object on the page.

    if (browserType == "NN4") {
       var clickX = evt.pageX;
       var clickY = evt.pageY;
       var objLeft, objTop, objWidth, objHeight;


       // Was the click on the "Text Handle"?

       objLeft = eval(layerRef+'["movetext"]'+styleSwitch+'.left');
       objTop =  eval(layerRef+'["movetext"]'+styleSwitch+'.top');
       objWidth =  eval(layerRef+'["movetext"]'+styleSwitch+'.clip.width');
       objHeight =  eval(layerRef+'["movetext"]'+styleSwitch+'.clip.height');

       if ((clickX > objLeft) &&
           (clickX < objLeft + objWidth) &&
           (clickY > objTop) &&
           (clickY < objTop + objHeight)) {
           selectedObj = "movetext";
           return;        // YES, IT'S THE TEXT HANDLE
       }

       // Was the click on the moveable image?

       objLeft = eval(layerRef+'["imagearea"]'+styleSwitch+'.left');
       objTop =  eval(layerRef+'["imagearea"]'+styleSwitch+'.top');
       objWidth =  eval(layerRef+'["imagearea"]'+styleSwitch+'.clip.width');
       objHeight =  eval(layerRef+'["imagearea"]'+styleSwitch+'.clip.height');

       if ((clickX > objLeft) &&
           (clickX < objLeft + objWidth) &&
           (clickY > objTop) &&
           (clickY < objTop + objHeight)) {
           selectedObj = "imagearea";
           return;        // YES, IT'S THE IMAGE
       }

       // Was the click on one of the swatches?


       for (var i = swatches; i > 0; i--) {
           
          objLeft = eval(layerRef+'["nnswatch' + i + '"]'+styleSwitch+'.left');
          objTop =  eval(layerRef+'["nnswatch' + i + '"]'+styleSwitch+'.top');
          objWidth =  eval(layerRef+'["nnswatch' + i + '"]'+styleSwitch+'.clip.width');
          objHeight =  eval(layerRef+'["nnswatch' + i + '"]'+styleSwitch+'.clip.height');
          if ((clickX > objLeft) &&
              (clickX < objLeft + objWidth) &&
              (clickY > objTop) &&
              (clickY < objTop + objHeight)) {
              selectedObj = "nnswatch" + i;
              return;    // YES, AND WE KNOW WHICH ONE.
          }

       }

    // FOR INTERNET EXPLORER A CLICK RETURNS THE OBJECT CLICKED ON

    }else if (browserType == "IE4") {
       var imgObj = window.event.srcElement;
       selectedObj = imgObj.parentElement.id;
       if (selectedObj) {
          return;
       }
    }
    selectedObj = "screen";
    return;
 }

 
 function checkKeyPress(evt) {

    var theKey;

    if (browserType == "NN4") {
       theKey = evt.which;
    }else if (browserType == "IE4") {
       theKey = window.event.keyCode;
    }
    status = theKey;
 }
 
 // END DRAG ROUTINES FOR NN4 AND IE4 ===================================

 // BEGIN DRAG ROUTINES FOR NN5 =========================================
 
    var grabObj=null; //
	var divid, otherObjID, l1, l2, t1, t2;

	function setDrag() {
		if (browserType != "NN5") return;
		// It turns out that unless I explicitly define the top and left like this,
		// the DOM can't recognize it. Bug!!!
		divid=document.getElementById('ieswatch1');
		divid.style.top = "4";
		divid.style.left = "4";
		divid=document.getElementById('ieswatch2');
		divid.style.top = "4";
		divid.style.left = "410";
		divid=document.getElementById('ieswatch3');
		divid.style.top = "108";
		divid.style.left = "4";
		divid=document.getElementById('ieswatch4');
		divid.style.top = "108";
		divid.style.left = "108";
		divid=document.getElementById('ieswatch5');
		divid.style.top = "108";
		divid.style.left = "410";
		divid=document.getElementById('ieswatch6');
		divid.style.top = "312";
		divid.style.left = "108";
		divid=document.getElementById('ieswatch7');
		divid.style.top = "360";
		divid.style.left = "108";
		
		divid=document.getElementById('snum1');
		divid.style.top = "7";
		divid.style.left = "7";
		divid=document.getElementById('snum2');
		divid.style.top = "7";
		divid.style.left = "413";
		divid=document.getElementById('snum3');
		divid.style.top = "111";
		divid.style.left = "7";
		divid=document.getElementById('snum4');
		divid.style.top = "111";
		divid.style.left = "111";
		divid=document.getElementById('snum5');
		divid.style.top = "111";
		divid.style.left = "413";
		divid=document.getElementById('snum6');
		divid.style.top = "315";
		divid.style.left = "111";
		divid=document.getElementById('snum7');
		divid.style.top = "363";
		divid.style.left = "111";

		divid=document.getElementById('imagearea');
		divid.style.top = "22";
		divid.style.left = "30";
		divid=document.getElementById('movetext');
		divid.style.top = "180";
		divid.style.left = "150";
		divid=document.getElementById('text');
		divid.style.top = "195";
		divid.style.left = "150";

 		document.addEventListener('mousedown',mdownMz,true);
	}

    function mdownMz(e){ // mouse down
	  grabObj=e.target.parentNode;
	  selectedObj = grabObj.id
      grabObj.eX=window.scrollX+e.clientX;
      grabObj.eY=window.scrollY+e.clientY;
	  document.addEventListener('mousemove',mmoveMz,true);
      document.addEventListener('mouseup',  mupMz,  true);
      e.cancelBubble=true;
    }
    function mmoveMz(e){ // mouse move
      if(grabObj==null) return;
	  if (!grabObj.style) return;
      var ex=window.scrollX+e.clientX;
      var ey=window.scrollY+e.clientY;
	  l1 = parseInt(grabObj.style.left);
	  t1 = parseInt(grabObj.style.top);
      grabObj.style.left=parseInt(grabObj.style.left)+ex-grabObj.eX;
      grabObj.style.top =parseInt(grabObj.style.top )+ey-grabObj.eY;
      grabObj.eX=ex; grabObj.eY=ey;
	  l2 = parseInt(grabObj.style.left);
	  t2 = parseInt(grabObj.style.top);
	  
      otherObjID = null;
      if (selectedObj == "movetext") {
         otherObjID = "text";
      } else if (selectedObj.substr(2,6) == "swatch") {
         otherObjID = "snum" + selectedObj.substr(8,1);
      }
      if (otherObjID) {
		otherObj = document.getElementById(otherObjID);
		otherObj.style.left = parseInt(otherObj.style.left) + (l2-l1);
        otherObj.style.top = parseInt(otherObj.style.top) + (t2-t1);

        //moveLayerTo(otherObj,(window.event.clientX - offsetX1),(window.event.clientY - offsetY1));
      }
	  
	  
      e.cancelBubble=true;
    }
    function mupMz(e){ // mouse up
      if(grabObj==null) return;
      document.removeEventListener('mousemove',mmoveMz,false);
      document.removeEventListener('mouseup',  mupMz,  false);
      e.cancelBubble=true;
      grabObj=null;
    }

 // END DRAG ROUTINES FOR NN5 ===========================================
