home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 February / february_2000.iso / site building / GoLive 4.0 Tryout / data1.cab / Apps / Modules / JScripts / GlobalScripts / CSScriptLib.js < prev    next >
Encoding:
Text File  |  1999-08-05  |  31.5 KB  |  953 lines

  1. // CyberStudio Javascript Library
  2.  
  3.  
  4. // ------------------------------
  5. // Global Functions
  6. // ------------------------------
  7. CSAg = window.navigator.userAgent; CSBVers = parseInt(CSAg.charAt(CSAg.indexOf("/")+1),10);
  8. function IsIE() { return CSAg.indexOf("MSIE") > 0;}
  9. function CSIEStyl(s) { return document.all.tags("div")[s].style; }
  10. function CSNSStyl(s) { return CSFindElement(s,0); }
  11. function CSFindElement(n,ly) { if (CSBVers < 4) return document[n];
  12.     var curDoc = ly ? ly.document : document; var elem = curDoc[n];
  13.     if (!elem) { for (var i=0;i<curDoc.layers.length;i++) {
  14.         elem = CSFindElement(n,curDoc.layers[i]); if (elem) return elem; }}
  15.     return elem;
  16. }
  17. function CSSetStylePos(s,d,p) { if (IsIE()) { if (d == 0) CSIEStyl(s).posLeft = p; else CSIEStyl(s).posTop = p; }
  18.     else { if (d == 0) CSNSStyl(s).left = p; else CSNSStyl(s).top = p; } }
  19. function CSGetStylePos(s,d) { if (IsIE()) { if (d == 0) return CSIEStyl(s).posLeft; else return CSIEStyl(s).posTop; }
  20.     else { if (d == 0) return CSNSStyl(s).left; else return CSNSStyl(s).top; }}
  21. CSLoopIsRunning = false; CSFctArray = new Array; CSTimeoutID = null;
  22. function CSLoop() {    
  23.     CSLoopIsRunning = false;
  24.     for (i=0;i<CSFctArray.length;i++) {
  25.         var curFct = CSFctArray[i];
  26.         if (curFct)    {
  27.             if (curFct.DoFunction(curFct)) { CSLoopIsRunning = true; curFct.counter++; }
  28.             else CSFctArray[i] = 0;
  29.         }
  30.     }
  31.     if (CSLoopIsRunning) CSTimeoutID = setTimeout("CSLoop()", 1);
  32. }
  33. function CSStartFunction(fct,data) {
  34.     if (!CSLoopIsRunning) { CSFctArray = 0; CSFctArray = new Array; }
  35.     var fctInfo = new Object;
  36.     fctInfo.DoFunction = fct; fctInfo.counter = 0; fctInfo.data = data;
  37.     CSFctArray[CSFctArray.length] = fctInfo; 
  38.     if (!CSLoopIsRunning) CSLoop();
  39. }
  40. function CSStopFunction(sceneName) {
  41.     var i;
  42.     for (i=0;i<CSFctArray.length;i++) {
  43.         var curFct = CSFctArray[i];
  44.         if (curFct){ if (curFct.data.name == sceneName){ CSFctArray[i] = 0; return; } }
  45.     }
  46. }
  47. function CSStopComplete() {
  48.     if (CSTimeoutID == null) return;
  49.     clearTimeout (CSTimeoutID); CSLoopIsRunning = false; CSTimeoutID = null;
  50. }
  51. function CSMoveLoop(fInf) {
  52.     var ticks = 60 * (((new Date()).getTime()) - fInf.data.startTime)/1000;
  53.     var f = ticks/fInf.data.ticks;
  54.     if (f < 1) { CSSetStylePos(fInf.data.layer,0,fInf.data.start[0] * (1-f) + fInf.data.end[0] * f);
  55.         CSSetStylePos(fInf.data.layer,1,fInf.data.start[1] * (1-f) + fInf.data.end[1] * f); return true; }
  56.     else { CSSetStylePos(fInf.data.layer,0,fInf.data.end[0]);
  57.         CSSetStylePos(fInf.data.layer,1,fInf.data.end[1]); }
  58.     return false;
  59. }
  60. function CSSlideObj (layer,start,end,ticks,startTime) {
  61.     this.layer=layer;this.start=start;this.end=end;this.ticks=ticks;this.startTime=startTime;
  62. }
  63. function CSSlideLayer(l,pos,anim,ticks) {
  64.     var x = pos[0]; var y = pos[1];
  65.  
  66.     if (l == '') return;
  67.     if (!anim) { CSSetStylePos(l,0,x); CSSetStylePos(l,1,y); }
  68.     else {  var fctData = new CSSlideObj(l,new Array(CSGetStylePos(l,0),CSGetStylePos(l,1)),new Array(x,y),ticks,(new Date()).getTime()); CSStartFunction(CSMoveLoop,fctData); }
  69. }
  70. function CSSetStyleVis(s,v) { if (IsIE()) CSIEStyl(s).visibility = (v == 0) ? "hidden" : "visible";
  71.     else CSNSStyl(s).visibility = (v == 0) ? 'hide' : 'show'; }
  72. function CSGetStyleVis(s) { if (IsIE()) return (CSIEStyl(s).visibility == "hidden") ? 0 : 1;
  73.     else return (CSNSStyl(s).visibility == 'hide') ? 0 : 1;}
  74. function CSGetLayerClip (el) {
  75.     if (el.isIE) return (new CSRect(0,0,el.offsetWidth,el.offsetHeight));
  76.     else return (new CSRect(el.clip.left,el.clip.top,el.clip.width,el.clip.height));
  77. }
  78. function CSSetLayerClip (el,clipRect) {
  79.     var l,t,r,b;
  80.     l=clipRect.left; t=clipRect.top; r=l+clipRect.width; b=t+clipRect.height;
  81.     if(el.isIE) { el.style.clip = "rect("+ t + " " + r + " " + b + " " + l + ")"; }
  82.     else {
  83.         el.clip.left=l; el.clip.top=t; 
  84.         el.clip.width=clipRect.width; el.clip.height=clipRect.height;
  85.     }
  86.     CSSetStyleVis(el.layer);
  87. }
  88. function CSRect (left,top,width,height) {
  89. this.left=left; this.top=top; this.width=width; this.height=height;
  90. }
  91. function CSCreateTransElement (layer, steps) {
  92.     var el;
  93.     if (IsIE()) el=document.all.tags("div")[layer];
  94.     else el=CSNSStyl(layer);
  95.     if (el==null) return null;
  96.     if (el.locked && (el.locked == true)) return null;
  97.     el.isIE=IsIE();
  98.     el.clipRect=CSGetLayerClip(el);
  99.     if (el.clipRect==null) return null;
  100.     el.maxValue=steps;
  101.     if (el.maxValue<=0) el.maxValue=30;
  102.     el.modus=""; el.layer=layer;
  103.     el.width=el.clipRect.width; el.height=el.clipRect.height;
  104.     el.locked = true;
  105.     return el;
  106. }
  107. function CSDisposeTransElement (el) { el.locked = false; }
  108. CSStateArray = new Object;
  109. CSCookieArray = new Object;
  110. CSCookieValArray = new Object;
  111.  
  112. function CSWriteCookie(action) {
  113.     var name   = "DFT" + action[1];
  114.     var hrs    = action[2];
  115.     var path   = action[3];
  116.     var domain = action[4];
  117.     var secure = action[5];
  118.     
  119.     var exp    = new Date((new Date()).getTime() + hrs * 3600000);
  120.     
  121.     var cookieVal = "";
  122.     for(var prop in CSCookieArray) {
  123.         if(("DFT" + CSCookieArray[prop]) == name) {
  124.             if(cookieVal != "") cookieVal += "&";
  125.             cookieVal += prop + ":" + escape(CSStateArray[prop]);
  126.         }
  127.     }
  128.     if(hrs != 0)
  129.         cookieVal += "; expires=" + exp.toGMTString();
  130.     if(path != "")
  131.         cookieVal += "; path=" + path;
  132.     if(domain != "")
  133.         cookieVal += "; domain=" + domain;
  134.     if(secure == true)
  135.         cookieVal += "; secure";
  136.         
  137.     //alert(cookieVal);
  138.     document.cookie = name + '=' + cookieVal;
  139. }
  140.  
  141. function CSReadCookie(action) {
  142.     var name    = "DFT" + action[1];
  143.     var cookies = document.cookie;
  144.  
  145.     if(cookies == "") return;
  146.  
  147.     var start = cookies.indexOf(name);
  148.     if(start == -1) return;
  149.  
  150.     start += name.length + 1;
  151.     var end = cookies.indexOf(";", start);
  152.     if(end == -1) end = cookies.length;
  153.         
  154.     var cookieVal = cookies.substring(start, end);
  155.     
  156.     var arr = cookieVal.split('&');
  157.     for(var i = 0; i < arr.length; i++) {
  158.         var a = arr[i].split(':');
  159.         CSStateArray[a[0]] = unescape(a[1]);
  160.     }    
  161. }
  162.  
  163. function CSDefineState(action) {
  164.     CSCookieArray[action[1]] = action[3]; 
  165. }
  166.  
  167. function CSSetState(action) {
  168.     CSStateArray[action[1]] = action[2];
  169. }
  170.  
  171. function CSInitState(action) {
  172.     if(typeof(CSStateArray[action[1]]) == "undefined")
  173.         CSStateArray[action[1]] = action[2];
  174. }
  175.  
  176. function CSCheckState(action) {
  177.     var obj1 = CSStateArray[action[1]];
  178.     var obj2 = action[2];
  179.  
  180.     if(typeof(obj1) == "object") {
  181.         for(var i=0;i<obj1.length;i++) {
  182.             if(obj1[i] != obj2[i])
  183.                 return false;
  184.             }
  185.         return true;
  186.         }
  187.         
  188.     var res;
  189.     var op = action[3];
  190.              if(op == "==") res = (CSStateArray[action[1]] == action[2]);    
  191.         else if(op == "!=") res = (CSStateArray[action[1]] != action[2]);    
  192.         else if(op == ">" ) res = (CSStateArray[action[1]] >  action[2]);    
  193.         else if(op == ">=") res = (CSStateArray[action[1]] >= action[2]);    
  194.         else if(op == "<" ) res = (CSStateArray[action[1]] <  action[2]);    
  195.         else if(op == "<=") res = (CSStateArray[action[1]] <= action[2]);    
  196.  
  197.     return res;
  198. }
  199.  
  200.  
  201. function CSScriptInit() {
  202. idxArray = new Array;
  203. for(var i=0;i<CSInit.length;i++)
  204.     idxArray[i] = i;
  205. CSAction2(CSInit, idxArray);
  206.  
  207. }
  208.  
  209. function CSScriptExit() {
  210. idxArray = new Array;
  211. for(var i=0;i<CSExit.length;i++)
  212.     idxArray[i] = i;
  213. CSAction2(CSExit, idxArray);
  214.  
  215. }
  216. CSStopExecution = false;
  217. CSInit = new Array;
  218. CSExit = new Array;
  219. CSStopExecution = false;
  220.  
  221. function CSAction(array) { 
  222.     return CSAction2(CSAct, array);
  223. }
  224. function CSAction2(fct, array) { 
  225.     var result;
  226.     for (var i=0;i<array.length;i++) {
  227.         if(CSStopExecution) return false; 
  228.         var actArray = fct[array[i]];
  229.         var tempArray = new Array;
  230.         for(var j=1;j<actArray.length;j++) {
  231.             if((actArray[j] != null) && (typeof(actArray[j]) == "object") && (actArray[j].length == 2)) {
  232.                 if(actArray[j][0] == "VAR") {
  233.                     tempArray[j] = CSStateArray[actArray[j][1]];
  234.                 }
  235.                 else {
  236.                     if(actArray[j][0] == "ACT") {
  237.                         tempArray[j] = CSAction(new Array(new String(actArray[j][1])));
  238.                     }
  239.                 else
  240.                     tempArray[j] = actArray[j];
  241.                 }
  242.             }
  243.             else
  244.                 tempArray[j] = actArray[j];
  245.         }            
  246.         result = actArray[0](tempArray);
  247.     }
  248.     return result;
  249. }
  250. CSAct = new Object;
  251. CSIm = new Object();
  252. function CSIShow(n,i) {
  253.     if (document.images) {
  254.         if (CSIm[n]) {
  255.             var img = (!IsIE()) ? CSFindElement(n,0) : document[n];
  256.             if (img && typeof(CSIm[n][i].src) != "undefined") {img.src = CSIm[n][i].src;}
  257.             if(i != 0)
  258.                 self.status = CSIm[n][3];
  259.             else
  260.                 self.status = " ";
  261.             return true;
  262.         }
  263.     }
  264.     return false;
  265. }
  266. function CSILoad(action) {
  267.     im = action[1];
  268.     if (document.images) {
  269.         CSIm[im] = new Object();
  270.         for (var i=2;i<5;i++) {
  271.             if (action[i] != '') { CSIm[im][i-2] = new Image(); CSIm[im][i-2].src = action[i]; }
  272.             else CSIm[im][i-2] = 0;
  273.         }
  274.         CSIm[im][3] = action[5];
  275.     }
  276. }
  277. function CSClickReturn () {
  278.     var bAgent = window.navigator.userAgent; 
  279.     var bAppName = window.navigator.appName;
  280.     if ((bAppName.indexOf("Explorer") >= 0) && (bAgent.indexOf("Mozilla/3") >= 0) && (bAgent.indexOf("Mac") >= 0))
  281.         return true; // dont follow link
  282.     else return false; // dont follow link
  283. }
  284. function CSButtonReturn () {
  285.     var bAgent = window.navigator.userAgent; 
  286.     var bAppName = window.navigator.appName;
  287.     if ((bAppName.indexOf("Explorer") >= 0) && (bAgent.indexOf("Mozilla/3") >= 0) && (bAgent.indexOf("Mac") >= 0))
  288.         return false; // follow link
  289.     else return true; // follow link
  290. }
  291. function CSBrowserSwitch(action) {
  292.     var bAgent    = window.navigator.userAgent;
  293.     var bAppName    = window.navigator.appName;
  294.  
  295.     var isNS        = (bAppName.indexOf("Netscape") >= 0);
  296.     var isIE        = (bAppName.indexOf("Explorer") >= 0);
  297.     var isWin        = (bAgent.indexOf("Win") >= 0); 
  298.     var isMac        = (bAgent.indexOf("Mac") >= 0); 
  299.  
  300.     var vers        = 0;
  301.     var versIdx    = (bAgent.indexOf("Mozilla/"));
  302.  
  303.     if(versIdx >= 0)
  304.         {
  305.         var sstr    = bAgent.substring(versIdx + 8, versIdx + 9);
  306.         vers        = parseInt(sstr) - 2;
  307.         }
  308.  
  309.     var url        = action[1];
  310.     var platform    = action[2];
  311.  
  312.     var versVec;
  313.     if(platform)
  314.         {
  315.         if(isNS && isMac) versVec = action[3];
  316.         if(isIE && isMac) versVec = action[4];
  317.         if(isNS && isWin) versVec = action[5];
  318.         if(isIE && isWin) versVec = action[6];
  319.         }
  320.     else
  321.         {
  322.         if(isNS) versVec = action[3];
  323.         if(isIE) versVec = action[4];
  324.         }
  325.  
  326.     if(vers > (versVec.length-1))
  327.         vers = versVec.length-1;
  328.     if(versVec[vers] == 0)
  329.         {
  330.         location            = url;
  331.         CSStopExecution    = true;    
  332.         }
  333. }
  334.  
  335. function CSURLPopupShow(formName, popupName, target) {
  336.     var form  = CSFindElement(formName);
  337.     var popup = form.elements[popupName];
  338.     window.open(popup.options[popup.selectedIndex].value, target);
  339.     popup.selectedIndex = 0;
  340. }
  341. function CSSetStyleDepth(style,depth) { if (IsIE()) CSIEStyl(style).zIndex = depth; else CSNSStyl(style).zIndex = depth;}
  342. function CSGetStyleDepth(style) { if (IsIE()) return (CSIEStyl(style).zIndex); else return (CSNSStyl(style).zIndex); }
  343. CSSeqArray = new Array;
  344. function CSSeqActionFct(seq,loopCount,continueLoop) {
  345.     if ((seq.loop < 2) || ((loopCount % 2) != 0)) {
  346.         for (var i=0;i<seq.actionCount;i++) {
  347.             if (seq.actions[3*i + 1] <= seq.frame) {
  348.                 if ((loopCount > 1) && (seq.actions[3*i + 1] < seq.start)) continue;
  349.                 if (seq.actions[3*i + 2] < loopCount) {
  350.                     seq.actions[3*i + 2] = loopCount; CSLoopIsRunning = true;
  351.                     CSAction(new Array(seq.actions[3*i + 0])); continueLoop = true;
  352.                 }
  353.             } else { continueLoop = true; break; }
  354.         }
  355.     } else {
  356.         for (var i=seq.actionCount-1;i>=0;i--) {
  357.             if (seq.actions[3*i + 1] > seq.frame) {
  358.                 if (seq.actions[3*i + 1] > seq.end) continue;
  359.                 if (seq.actions[3*i + 2] < loopCount) {
  360.                     seq.actions[3*i + 2] = loopCount; CSLoopIsRunning = true;
  361.                     CSAction(new Array(seq.actions[3*i + 0])); continueLoop = true;
  362.                 }
  363.             } else { continueLoop = true; break; }
  364.         }
  365.     }
  366.     return continueLoop;
  367. }        
  368. function CSSeqFunction(fctInfo)
  369. {
  370.     var seq = fctInfo.data; var oldFrame = seq.frame;
  371.     var newTicks = (new Date()).getTime();
  372.     seq.frame = Math.round((seq.fps * (newTicks - seq.startTicks)/1000.0) - 0.5);
  373.     var continueLoop  = false; var loopCount = 1;
  374.     
  375.     if (seq.loop > 0) {
  376.         continueLoop = true;
  377.         if (seq.loop == 1) {
  378.             var iv = (seq.end - seq.start);
  379.             var f = Math.round(((seq.frame - seq.start) / iv) - 0.5);
  380.             if (f < 0) f = 0;
  381.             loopCount = f+1;
  382.             seq.frame = seq.start + ((seq.frame - seq.start) % (seq.end - seq.start));
  383.         } else {
  384.             var iv = (seq.end - seq.start);
  385.             var f = Math.round(((seq.frame - seq.start) / iv) - 0.5);
  386.             if (f < 0) f = 0;
  387.             loopCount = f+1;
  388.             f = (seq.frame - seq.start) % (2 * iv);
  389.             if (f > iv) f = 2*iv - f;
  390.             seq.frame = seq.start + f;
  391.         }
  392.     }
  393.     continueLoop = CSSeqActionFct(seq,loopCount,continueLoop);
  394.     for (var i=0;i<seq.tracks.length;i++) {
  395.         var track = seq.tracks[i]; var frameCount = 0; var lastCount = 0; var partCount = 0;
  396.         var partIdx = track.parts.ticks.length;
  397.         for (var k=0;k<track.parts.ticks.length;k++) {
  398.             frameCount += track.parts.ticks[k];
  399.             if (frameCount > seq.frame) { partIdx = k; partCount = seq.frame - lastCount; break; }
  400.             lastCount = frameCount;
  401.         }
  402.         if (partIdx < track.parts.ticks.length) {
  403.             var type=track.parts.moveType[partIdx];
  404.             if(type==1) CSSetLinearPos (track, partIdx, partCount);
  405.             else if(type==2) CSSetCurvePos (track, partIdx, partCount);
  406.             else if(type==3) if (oldFrame != seq.frame) CSSetRandomPos (track, partIdx, partCount);
  407.                              else { x = CSGetStylePos(track.layer,0); y = CSGetStylePos(track.layer,1); }
  408.             CSSetStyleVis(track.layer,track.parts.visibilities[partIdx]);
  409.             CSSetStyleDepth(track.layer,track.parts.depths[partIdx]);
  410.             continueLoop = true;
  411.         } else {
  412.             var partIdx = track.parts.moveType.length-1;
  413.             var posArray = track.parts.positions;
  414.             var x = posArray[partIdx * 6 + 0]; var y = posArray[partIdx * 6 + 1];
  415.             CSSetStylePos(track.layer,0,x); CSSetStylePos(track.layer,1,y);
  416.             CSSetStyleVis(track.layer,track.parts.visibilities[partIdx]);
  417.             CSSetStyleDepth(track.layer,track.parts.depths[partIdx]);
  418.         }
  419.     }
  420.     return continueLoop;
  421. }
  422. function CSSetLinearPos (track, partIdx, partCount) {
  423.     var curTicks = track.parts.ticks[partIdx];
  424.     var pIdx1 = partIdx * 6; var pIdx2 = (partIdx+1) * 6;
  425.     var posArray = track.parts.positions;
  426.     var x = posArray[pIdx1 + 0]; var y = posArray[pIdx1 + 1];
  427.     var x1,x2,y1,y2;
  428.     var factor = partCount/curTicks;
  429.     x1 = x; y1 = y;
  430.     x2 = posArray[pIdx2 + 0]; y2 = posArray[pIdx2 + 1];
  431.     x = x1 * (1-factor) + x2 * factor; y = y1 * (1-factor) + y2 * factor;
  432.     CSSetStylePos(track.layer,0,x); CSSetStylePos(track.layer,1,y);
  433. }
  434. function CSSetCurvePos (track, partIdx, partCount) {
  435.     var curTicks = track.parts.ticks[partIdx];
  436.     var pIdx1 = partIdx * 6; var pIdx2 = (partIdx+1) * 6;
  437.     var posArray = track.parts.positions;
  438.     var x = posArray[pIdx1 + 0]; var y = posArray[pIdx1 + 1];
  439.     var x1,x2,x3,x4,y1,y2,y3,y4;
  440.     var factor = partCount/curTicks;
  441.     var t = factor; var u = t * t; var v = u * t;
  442.     var val1 = 3*(u-t) - v + 1; var val2 = 3*(v+t - 2*u); var val3 = 3*(u-v); var val4 = v;
  443.     x1 = x; y1 = y; x2 = posArray[pIdx1 + 2]; y2 = posArray[pIdx1 + 3];
  444.     x3 = posArray[pIdx1 + 4]; y3 = posArray[pIdx1 + 5];
  445.     x4 = posArray[pIdx2 + 0]; y4 = posArray[pIdx2 + 1];
  446.     x = x1 * val1 + x2 * val2 + x3 * val3 + x4 * val4;
  447.     y = y1 * val1 + y2 * val2 + y3 * val3 + y4 * val4;
  448.     CSSetStylePos(track.layer,0,x); CSSetStylePos(track.layer,1,y);
  449. }
  450. function CSSetRandomPos (track, partIdx, partCount) {
  451.     var curTicks = track.parts.ticks[partIdx];
  452.     var pIdx1 = partIdx * 6; var pIdx2 = (partIdx+1) * 6;
  453.     var posArray = track.parts.positions;
  454.     var x = posArray[pIdx1 + 0]; var y = posArray[pIdx1 + 1];
  455.     var x1,x2,y1,y2;
  456.     var factor = partCount/curTicks;
  457.     x1 = x; y1 = y;
  458.     x2 = posArray[pIdx2 + 0]; y2 = posArray[pIdx2 + 1];
  459.     var factorx = Math.random(); var factory = Math.random();
  460.     x = x1 * (1-factorx) + x2 * factorx; y = y1 * (1-factory) + y2 * factory;
  461.     CSSetStylePos(track.layer,0,x); CSSetStylePos(track.layer,1,y);
  462. }
  463. function CSStartSeq(name) {
  464.     var seq = CSGetScene(name); var date = new Date()
  465.     seq.startTicks = date.getTime()
  466.     for (var i=0;i<seq.actionCount;i++) seq.actions[3*i+2] = 0;
  467.     CSStartFunction(CSSeqFunction,seq);
  468. }
  469. function CSSceneObj (name,fps,loop,start,end,frame,sTicks,numAct,acts,tracks) {
  470.     this.name=name;this.fps=fps;this.loop=loop;this.start=start;this.end=end;
  471.     this.frame=frame;this.startTicks=sTicks;this.actionCount=numAct;
  472.     this.actions=acts;this.tracks=tracks;
  473. }
  474. function CSTrackObj (name,partIdx,partCount,parts) {
  475.     this.layer=name;this.partIdx=partIdx;this.partCount=partCount;this.parts=parts;
  476. }
  477. function CSPartObj (ticks,pos,depths,vis,moveType) {
  478.     this.ticks=ticks;this.positions=pos;this.depths=depths;this.visibilities=vis;
  479.     this.moveType=moveType;
  480. }
  481. function CSGetScene (name) {
  482.     for (i=0;i<CSSeqArray.length;i++) { var seq = CSSeqArray[i]; if (seq.name==name) return seq; }
  483.     return 0;
  484. }
  485. function CSAutoStartScene(action) { CSStartSeq (action[1]); }
  486.  
  487.  
  488. // ------------------------------
  489. // Action Functions
  490. // ------------------------------
  491.  
  492. function CSGetLayerPos(action) { 
  493.     var layer = action[1];
  494.     var x        = CSGetStylePos(layer, 0);
  495.     var y        = CSGetStylePos(layer, 1);
  496.     return new Array(x, y);
  497. }
  498. function CSGetFormElementValue(action) { 
  499.     var form = action[1];
  500.     var elem = action[2];
  501.     return document.forms[form].elements[elem].value;
  502. }
  503. CSImages=new Array();
  504. function CSPreloadImage(action) {
  505.     if (document.images) { CSImages[CSImages.length]=new Image(); CSImages[CSImages.length-1].src=action[1]; }
  506. }
  507.  
  508. CSImages=new Array();
  509. function CSPreloadImage(action) {
  510.     if (document.images) { CSImages[CSImages.length]=new Image(); CSImages[CSImages.length-1].src=action[1]; }
  511. }
  512. function CSRandomImg(action) { 
  513.     if (document.images) {
  514.         var img = null;
  515.         var whichone = Math.floor((Math.random() * 10)) % 3
  516.         if(!IsIE()) img = CSFindElement(action[1],0);
  517.         else img = document.images[action[1]];
  518.         img.src = action[whichone+2]
  519.     }
  520.  }
  521. function CSSetImageURL(action) {
  522.     var img = null;
  523.     if (document.images) {
  524.         if (!IsIE()) img = CSFindElement(action[1],0);
  525.         else img = document.images[action[1]];
  526.         if (img) img.src = action[2];
  527.     }
  528. }
  529. function CSGoBack1() { history.back() }
  530. function CSGotoLink(action) {
  531.     if (action[2].length) {
  532.         var hasFrame=false;
  533.         for(i=0;i<parent.frames.length;i++) { if (parent.frames[i].name==action[2]) { hasFrame=true; break;}}
  534.         if (hasFrame==true)
  535.             parent.frames[action[2]].location = action[1];
  536.         else
  537.             window.open (action[1],action[2],"");
  538.     }
  539.     else location = action[1];
  540. }
  541. function CSHistoryGo(action) { history.go(action[1]); }
  542. function CSOpenWindow(action) {
  543.     var wf = "";    
  544.     wf = wf + "width=" + action[3];
  545.     wf = wf + ",height=" + action[4];
  546.     wf = wf + ",resizable=" + (action[5] ? "yes" : "no");
  547.     wf = wf + ",scrollbars=" + (action[6] ? "yes" : "no");
  548.     wf = wf + ",menubar=" + (action[7] ? "yes" : "no");
  549.     wf = wf + ",toolbar=" + (action[8] ? "yes" : "no");
  550.     wf = wf + ",directories=" + (action[9] ? "yes" : "no");
  551.     wf = wf + ",location=" + (action[10] ? "yes" : "no");
  552.     wf = wf + ",status=" + (action[11] ? "yes" : "no");        
  553.     window.open(action[1],action[2],wf);
  554. }
  555. function CSDocWrite(action) { document.write(action[1]); }
  556. function CSOpenAlert(action) { alert(action[1]); }
  557. function CSSetStatus(action) { self.status = action[1]; }
  558. var gCSIEDragObject = null;
  559. function CSSetupDrag (layerName) {
  560.     this.x = 0; this.y = 0;
  561.     if (IsIE()) {
  562.         this.canDrag=true; 
  563.         this.layerObj=document.all.tags("div")[layerName];
  564.         this.layerObj.dragObj = this;
  565.         document.ondragstart = CSIEStartDrag;
  566.         document.onmousedown = CSIEMouseDown;
  567.         document.onmouseup = CSIEStopDrag;
  568.     } else {
  569.         this.layer=CSNSStyl(layerName);this.onmousemove=null; 
  570.         this.layer.document.theLayer=this;
  571.         this.layer.document.captureEvents(Event.MOUSEDOWN);
  572.         this.layer.document.onmousedown=CSNSStartDrag; 
  573.         this.layer.document.onmouseup=CSNSStopDrag;
  574.     }
  575. }
  576. function CSNSStartDrag (ev) {
  577.     var clickInMe = false;
  578.     if (ev.target != this) {
  579.         for (var i=0;i<this.images.length;i++) {
  580.             if (this.images[i] == ev.target) { clickInMe = true; break;}
  581.             }
  582.         }
  583.     else clickInMe = true;    
  584.     if (clickInMe)
  585.         {
  586.         this.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP); 
  587.         this.onmousemove=CSNSDoDrag;
  588.         this.theLayer.x= ev.pageX;
  589.         this.theLayer.y= ev.pageY;
  590.         this.routeEvent(ev);
  591.         return false;
  592.         }
  593.    this.onmousemove=null;this.releaseEvents(Event.MOUSEMOVE|Event.MOUSEUP);
  594.     this.routeEvent(ev);
  595.    return true; 
  596. }
  597. function CSNSStopDrag (ev) {
  598.    this.onmousemove=null;this.releaseEvents(Event.MOUSEMOVE|Event.MOUSEUP);return false; 
  599. }
  600. function CSNSDoDrag (ev) {
  601.     this.theLayer.layer.moveBy(ev.pageX-this.theLayer.x, ev.pageY-this.theLayer.y); 
  602.     this.theLayer.x = ev.pageX; 
  603.     this.theLayer.y = ev.pageY;
  604.     this.routeEvent(ev);
  605. }
  606. function CSIEStartDrag () {
  607.     if(gCSIEDragObject != null && (gCSIEDragObject.tagName==event.srcElement.tagName))
  608.         event.returnValue=false;  
  609. }
  610. function CSIEStopDrag () { gCSIEDragObject=null; document.onmousemove=null; }
  611. function CSIEMouseDown () {
  612.     if(event.button==1) {
  613.         dragLayer = event.srcElement;
  614.         while (dragLayer!=null) 
  615.             {
  616.             if ((dragLayer.dragObj == null) && (dragLayer.tagName == "DIV"))
  617.                 break;
  618.             if (dragLayer.dragObj != null)
  619.                 break;
  620.             dragLayer=dragLayer.parentElement;
  621.             }
  622.             
  623.         if (dragLayer == null) return;
  624.         if (dragLayer.dragObj!=null && dragLayer.dragObj.canDrag) {
  625.             gCSIEDragObject = dragLayer;
  626.             gCSIEDragObject.dragObj.x=event.clientX;
  627.             gCSIEDragObject.dragObj.y=event.clientY;
  628.             document.onmousemove = CSIEMouseMove;
  629.         }
  630.     }
  631. }
  632. function CSIEMouseMove () {
  633.     gCSIEDragObject.dragObj.layerObj.style.pixelLeft+=(event.clientX-gCSIEDragObject.dragObj.x);
  634.     gCSIEDragObject.dragObj.layerObj.style.pixelTop+=(event.clientY-gCSIEDragObject.dragObj.y);
  635.     gCSIEDragObject.dragObj.x=event.clientX;
  636.     gCSIEDragObject.dragObj.y=event.clientY;
  637.     event.returnValue = false;
  638.     event.cancelBubble = true;
  639. }
  640. var gDragArray = new Array();
  641. function CSDrag(action) { gDragArray[gDragArray.length] = new CSSetupDrag(action[1]); }
  642. function CSFlipMove(action) {
  643.     if (action[1] == '') return;
  644.     var curX = CSGetStylePos(action[1],0); var curY = CSGetStylePos(action[1],1);
  645.     var x1 = action[2][0];
  646.     var y1 = action[2][1];
  647.     if ((x1 != curX) || (y1 != curY)) CSSlideLayer(action[1],action[2],action[4],action[5]);
  648.     else CSSlideLayer(action[1],action[3],action[4],action[5]);
  649. }
  650. function CSMoveBy(action)
  651. {
  652.     x = CSGetStylePos(action[1], 0);
  653.     y = CSGetStylePos(action[1], 1);
  654.     x += parseInt(action[2]);
  655.     y += parseInt(action[3]);
  656.     x = CSSetStylePos(action[1], 0, x);
  657.     y = CSSetStylePos(action[1], 1, y);
  658. }
  659. function CSMoveTo(action) { CSSlideLayer(action[1],action[2],action[3],action[4]); }
  660. function CSPlayScene(action) { CSStartSeq (action[1]); }
  661.  
  662. var CSLastSound = null
  663. function CSPlaySound(action) {
  664.     if (eval('document.'+action[1])!=null) {
  665.         if (CSLastSound != null && CSLastSound != action[1]) eval ('document.' + CSLastSound + '.stop()');
  666.         CSLastSound = action[1]
  667.         if (window.navigator.userAgent.indexOf("MSIE") > 0) eval ('document.' + CSLastSound + '.run()');
  668.         else eval ('document.' + CSLastSound + '.play(true)');
  669.     } else { alert ("The current Plug-In can not be controled by JavaScript. Please try using LiveAudio or a compatible Plug-In!"); }
  670. }
  671.  
  672. function CSShowHide(action) {
  673.     if (action[1] == '') return;
  674.     var type=action[2];
  675.     if(type==0) CSSetStyleVis(action[1],0);
  676.     else if(type==1) CSSetStyleVis(action[1],1);
  677.     else if(type==2) { 
  678.         if (CSGetStyleVis(action[1]) == 0) CSSetStyleVis(action[1],1);
  679.         else CSSetStyleVis(action[1],0);
  680.     }
  681. }
  682. function CSStopAll(action) { CSStopComplete (); }
  683.  
  684. function CSStopScene(action) { CSStopFunction (action[1]); }
  685.  
  686. function CSStopSound (action) { if (eval('document.'+action[1])!=null) { eval ('document.' + action[1] + '.stop()');}}
  687.  
  688. function CSStartWipe (action)
  689. {
  690.     var el=CSCreateTransElement (action[1], action[2]);
  691.     if (el==null) return;
  692.     var dir=action[3];
  693.     if (dir=="_inLeft") {el.steps=el.clipRect.width/el.maxValue; el.modus="in";}
  694.     else if (dir=="_inRight") {el.steps=el.clipRect.width/el.maxValue; el.modus="in";}
  695.     else if (dir=="_outLeft") {el.steps=el.clipRect.width/el.maxValue; el.modus="out";}
  696.     else if (dir=="_outRight") {el.steps=el.clipRect.width/el.maxValue; el.modus="out";}
  697.     else if (dir=="_inTop") {el.steps=el.clipRect.height/el.maxValue; el.modus="in";}
  698.     else if (dir=="_inBottom") {el.steps=el.clipRect.height/el.maxValue; el.modus="in";}
  699.     else if (dir=="_outTop") {el.steps=el.clipRect.height/el.maxValue; el.modus="out";}
  700.     else if (dir=="_outBottom") {el.steps=el.clipRect.height/el.maxValue; el.modus="out";}
  701.     else if (dir=="_inCenter") {el.HSteps=el.clipRect.width/el.maxValue; el.VSteps=el.clipRect.height/el.maxValue; el.modus="in";}
  702.     else if (dir=="_outCenter") {el.HSteps=el.clipRect.width/el.maxValue; el.VSteps=el.clipRect.height/el.maxValue; el.modus="out";}
  703.     if (el.modus=="") return;
  704.     el.currentValue=0;
  705.     el.dir=action[3];
  706.     CSStartFunction(CSDoWipe,el);
  707. }
  708. function CSDoWipe (info)
  709. {
  710.     var el = info.data;
  711.     if (el==null) return false;
  712.     if (el.currentValue==el.maxValue) { CSFinishWipe(el); return false; }
  713.     var r = new CSRect(el.clipRect.left,el.clipRect.top,el.clipRect.width,el.clipRect.height);
  714.     var dir=el.dir;
  715.     if (dir=="_inLeft") {r.left=r.width-el.currentValue*el.steps;}
  716.     else if (dir=="_inTop") {r.top=r.height-el.currentValue*el.steps;}
  717.     else if (dir=="_inRight") {r.width=el.currentValue*el.steps;}
  718.     else if (dir=="_inBottom") {r.height=el.currentValue*el.steps;}
  719.     else if (dir=="_outLeft") {r.width=r.width-el.currentValue*el.steps;}
  720.     else if (dir=="_outTop") {r.height=r.height-el.currentValue*el.steps;}
  721.     else if (dir=="_outRight") {r.left=el.currentValue*el.steps;}
  722.     else if (dir=="_outBottom") {r.top=el.currentValue*el.steps;}
  723.     else if (dir=="_inCenter") {r=CSCenterRectIn(el,r);}
  724.     else if (dir=="_outCenter") {r=CSCenterRectOut(el,r);}
  725.     CSSetLayerClip(el,r);
  726.     el.currentValue+=1;
  727.     return true;
  728. }
  729. function CSFinishWipe (el)
  730. {
  731.     if (el.modus=="in") CSSetLayerClip(el,el.clipRect);
  732.     else { 
  733.         el.clipRect=new CSRect(0,0,el.width,el.height); 
  734.         CSSetLayerClip(el,el.clipRect); 
  735.         CSSetStyleVis(el.layer,0);
  736.     }
  737.     CSDisposeTransElement(el);
  738. }
  739. function CSCenterRectIn(el,r)
  740. {
  741.     var hValue= el.currentValue*el.HSteps/2;
  742.     var vValue= el.currentValue*el.VSteps/2;
  743.     r.left=Math.round(r.left+r.width/2-hValue); 
  744.     r.top=Math.round(r.top+r.height/2-vValue); 
  745.     r.width=Math.round(hValue*2);
  746.     r.height=Math.round(vValue*2);
  747.     return r;
  748. }
  749. function CSCenterRectOut(el,r)
  750. {
  751.     var hValue= el.currentValue*el.HSteps/2;
  752.     var vValue= el.currentValue*el.VSteps/2;
  753.     r.left+=Math.round(hValue); 
  754.     r.top+=Math.round(vValue); 
  755.     r.width-=Math.round(hValue*2);
  756.     r.height-=Math.round(vValue*2);
  757.     return r;
  758. }
  759. function CSDocWrite(action) { document.write(action[1]); }
  760.  
  761. function CSFixFct() {
  762.     var d = document; var w = window;
  763.     if (d.cs.csFix.w != w.innerWidth || d.cs.csFix.h != w.innerHeight) {
  764.         d.location = d.location; }
  765. }
  766. function CSNSFix(action) { 
  767.     var d = document; var w = window;
  768.     if ((navigator.appName == 'Netscape') && (parseInt(navigator.appVersion) == 4)) {
  769.         if (typeof d.cs == 'undefined') { 
  770.             d.cs = new Object;
  771.             d.cs.csFix = new Object; 
  772.         } else if (CSIsFrame (w) == true) CSFixFct();
  773.         d.cs.csFix.w = w.innerWidth;
  774.         d.cs.csFix.h = w.innerHeight; 
  775.         window.onresize = CSFixFct;
  776.       }
  777. }
  778. function CSIsFrame (window) {
  779.     var rootWindow = window.parent;
  780.     if (rootWindow == 'undefined') return false;
  781.     for (i = 0; i < rootWindow.frames.length; i++)
  782.         if (window == rootWindow.frames[i]) return true;
  783.     return false;
  784. }
  785.  
  786. function CSResizeWindow(action) { 
  787.     if(navigator.appVersion.charAt(0) >=4) { window.resizeTo (action[1],action[2]) }
  788. }
  789.  
  790. function CSScrollDown(action){
  791.     if(navigator.appVersion.charAt(0) >=4) {
  792.         var container = 0    
  793.         if (action[2] > 0)        {
  794.             while (container < action[1]) {
  795.                    window.scrollBy(0,action[2]);
  796.                    container = container + action[2];  
  797.             }     
  798.           }
  799.     }
  800. }
  801.  
  802. function CSScrollLeft(action){
  803.     if(navigator.appVersion.charAt(0) >=4) {
  804.         var container = 0    
  805.         if (action[2] > 0)        {
  806.             while (container < action[1]) {
  807.                    window.scrollBy(-action[2],0);
  808.                    container = container + action[2];  
  809.             }     
  810.           }
  811.     }
  812. }
  813.  
  814. function CSScrollRight(action){
  815.     if(navigator.appVersion.charAt(0) >=4) {
  816.         var container = 0    
  817.         if (action[2] > 0)        {
  818.             while (container < action[1]) {
  819.                    window.scrollBy(action[2],0);
  820.                    container = container + action[2];  
  821.             }     
  822.           }
  823.     }
  824. }
  825.  
  826. function CSScrollUp(action){
  827.     if(navigator.appVersion.charAt(0) >=4) {
  828.         var container = 0    
  829.         if (action[2] > 0)        {
  830.             while (container < action[1]) {
  831.                    window.scrollBy(0,-action[2]);
  832.                    container = container + action[2];  
  833.             }     
  834.           }
  835.     }
  836. }
  837.  
  838. function CSSetBackColor(action) { document.bgColor = action[1]; }
  839. function CSActionGroup (action) {
  840.     for(var i=1;i<action.length;i++) { CSAction(new Array(action[i])); }
  841. }
  842. function CSCallAction(action)
  843. {
  844.     CSAction(new Array(action[1]));
  845. }
  846. function CSCallFunction(action)
  847. {
  848.     var str = action[1];
  849.     str += "(";
  850.     str += action[2];
  851.     str += ");"
  852.  
  853.     return eval(str);
  854. }
  855. function CSConditionAction(action) {
  856.     if (action[1]) {
  857.         if (CSAction(new Array(action[1])) == true) {
  858.             if (action[2]) CSAction(new Array(action[2]));
  859.         } else if (action[3]) CSAction(new Array(action[3]));
  860.     }
  861. }
  862. function CSIdleObject (action) {
  863.     this.conditionAction = action[2];
  864.     this.trueAction = action[3];
  865.     this.falseAction = action[4];
  866.     this.exitIdleIfTrue = action[1];
  867.     this.lastState = false;
  868. }
  869. function CSIdleAction(action) {
  870.     idleObj = new CSIdleObject (action);
  871.     CSStartFunction (CSDoIdle,idleObj);
  872. }
  873. function CSDoIdle (param) {
  874.     idleObject=param.data;
  875.     if (idleObject.conditionAction) {
  876.         gCurrentIdleObject = idleObject;
  877.         var result = CSAction(new Array(idleObject.conditionAction));
  878.         if (result == true && idleObject.lastState==false) {
  879.             idleObject.lastState = result;
  880.             if (idleObject.trueAction) {
  881.                 CSAction(new Array(idleObject.trueAction));
  882.                 if (idleObject.exitIdleIfTrue == true) return false;
  883.             }
  884.         } else if (result == false && idleObject.lastState == true) {
  885.             idleObject.lastState = false;
  886.             if (idleObject.falseAction) {
  887.                 CSAction(new Array(idleObject.falseAction));
  888.             }        
  889.         }
  890.     }
  891.     return true;
  892. }
  893. function CSLayerIntersect (condition)
  894. {
  895.     var l1,t1,r1,b1,l2,t2,r2,b2;
  896.     if (IsIE()) {
  897.         var layer1=document.all.tags("div")[condition[1]];
  898.         var layer2=document.all.tags("div")[condition[2]];
  899.         l1=layer1.style.pixelLeft; t1=layer1.style.pixelTop; r1=layer1.offsetWidth+l1; b1=layer1.offsetHeight+t1;
  900.         l2=layer2.style.pixelLeft; t2=layer2.style.pixelTop; r2=layer2.offsetWidth+l2; b2=layer2.offsetHeight+t2;    
  901.     } else {
  902.         var layer1=CSNSStyl(condition[1]);
  903.         var layer2=CSNSStyl(condition[2]);
  904.         l1=layer1.x; t1=layer1.y; r1=layer1.clip.width+l1; b1=layer1.clip.height+t1;
  905.         l2=layer2.x; t2=layer2.y; r2=layer2.clip.width+l2; b2=layer2.clip.height+t2;
  906.     }
  907.     var w = (r1 < r2 ? r1 : r2) - (l1 > l2 ? l1 : l2)
  908.     var h = (b1 < b2 ? b1 : b2) - (t1 > t2 ? t1 : t2)
  909.     return ((w >= 0) && (h >= 0));
  910. }
  911. CSCurrentPressedKey = -1;
  912. function CSKeyPress(ev) {
  913.     var code;
  914.     if(IsIE()) CSCurrentPressedKey = event.keyCode;
  915.     else CSCurrentPressedKey = ev.which;
  916. }
  917. document.onkeypress    = CSKeyPress;
  918.  
  919. function CSKeyCompare(condition)
  920. {
  921.     var eq = (condition[1] == CSCurrentPressedKey);
  922.     if(eq)
  923.         CSCurrentPressedKey = -1;
  924.     return eq;
  925. }
  926. function CSTimeout (condition) {
  927.     var result = false;
  928.     if (gCurrentIdleObject.lastTime) {
  929.         var t=new Date();
  930.         if (t.getTime() >= gCurrentIdleObject.lastTime) { 
  931.             if (t.getTime() >= gCurrentIdleObject.nextTime) { 
  932.                 gCurrentIdleObject.lastTime = t.getTime() + condition[1]*1000;
  933.                 gCurrentIdleObject.nextTime = gCurrentIdleObject.lastTime + condition[1]*1000;
  934.                 return false;
  935.             }
  936.             return true;
  937.         }
  938.     } else { 
  939.         var t=new Date();
  940.         gCurrentIdleObject.lastTime = t.getTime() + condition[1]*1000;
  941.         gCurrentIdleObject.nextTime = gCurrentIdleObject.lastTime + condition[1]*1000;
  942.     }
  943.     return result;
  944. }
  945.  
  946.  
  947.  
  948.  
  949.  
  950.  
  951.  
  952. // EOF CyberStudio Javascript Library
  953.