prefs toc/folding
[lhc/web/wiklou.git] / stylesheets / sticky.js
1 // Make a layer that stays in the same place on screen when scrolling the browser window.
2 // Version 1.2
3 // See http://www.mark.ac/help for browser support.
4
5 var mySticky;
6 var theLayer;
7
8 // Setup variables for sliding.
9 // lastY and staticYOffset should match your CSS top definition.
10
11 lastY=10;YOffset=0;staticYOffset=10;refreshMS=25;
12
13
14 // Setup function that runs when the page loads.
15 function setup(eID){
16 bw=new checkBrowser;
17 if(bw.ns4||bw.opera){MM_reloadPage(true);}
18 var noFix=bw.ie4||bw.ns4||(bw.macie50)?true:false;
19 if (window.attachEvent){fix_bind()}
20 else if(noFix){
21 if(bw.ns6){document.getElementById(eID).style.position="absolute";}
22 if(bw.macie50){document.getElementById(eID).style.position="absolute";document.getElementById(eID).style.backgroundColor="#ccffcc";}
23 if(bw.ns6&&YOffset==0){YOffset=-15}
24 mySticky=new makeLayerObj(eID);
25 layerSlide(eID)}
26 else{
27 mySticky=new makeLayerObj(eID);
28 mySticky.css.position="fixed";}
29
30 if(!mySticky){mySticky=new makeLayerObj(eID);}
31 //mySticky.css.visibility="visible";
32 }
33
34
35 // -------------------------
36 // emulate css 'position: fixed' in IE5+ Win
37 // code by aclover@1value.com
38 fix_elements = new Array();
39
40 function fix_event(){
41 var i;
42 for (i=0; i < fix_elements.length; i++){
43 fix_elements[i].style.left = parseInt(fix_elements[i].fix_left)+document.getElementsByTagName('html')[0].scrollLeft+document.getElementsByTagName('body')[0].scrollLeft+'px';
44 fix_elements[i].style.top = parseInt(fix_elements[i].fix_top)+document.getElementsByTagName('html')[0].scrollTop+document.getElementsByTagName('body')[0].scrollTop+'px';
45 }
46 }
47
48 function fix_bind(){
49 var i;
50 for (i=0; i < document.all.length; i++){
51 if (document.all[i].currentStyle.position=='fixed'){
52 document.all[i].fix_left = document.all[i].currentStyle.left;
53 document.all[i].fix_top = document.all[i].currentStyle.top;
54 document.all[i].style.position = 'absolute';
55 fix_elements[fix_elements.length] = document.all[i];
56 window.attachEvent('onscroll', fix_event);
57 window.attachEvent('onresize', fix_event);
58 }
59 }
60 }
61 // -------------------------
62
63
64 // -------------------------
65 // DHTML menu sliding. Requires checkBrowser()
66 // Based on source at http://www.simplythebest.net/
67 function layerSlide(layerID) {
68 if(bw.dhtml){
69 if(!mySticky){mySticky=new makeLayerObj(layerID);}
70 if (bw.ns) {winY = window.pageYOffset;}
71 else if (bw.ie) {winY = document.body.scrollTop;}
72 if (bw.ie||bw.ns) {
73 if (winY!=lastY&&winY>YOffset-staticYOffset){smooth = .3 * (winY - lastY - YOffset + staticYOffset);}
74 else if (YOffset-staticYOffset+lastY>YOffset-staticYOffset){smooth = .3 * (winY - lastY - (YOffset-(YOffset-winY)));}
75 else{smooth=0}
76 if(smooth > 0) {smooth = Math.ceil(smooth);}
77 else{smooth = Math.floor(smooth);}
78 if (bw.ie){mySticky.css.pixelTop+=smooth;}
79 else if (bw.ns){mySticky.css.top=parseInt(mySticky.css.top)+smooth;}
80 lastY = lastY+smooth;
81 top.window.status=new Date()
82 setTimeout('layerSlide("'+layerID+'")', refreshMS)}}}
83 // -------------------------
84
85 // Netscape 4.x browser resize fix
86 function MM_reloadPage(init) {
87 if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
88 document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; top.onresize=MM_reloadPage; }}
89 else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) {location.reload();}}
90
91 // Create browser-independent layer and browser objects
92 function makeLayerObj(eID){
93 if(document.getElementById){this.css=document.getElementById(eID).style}
94 else if(document.layers){this.css=document.layers[eID];}
95 else if(document.all){this.css=document.all[eID].style;}
96 return this
97 }
98
99 function checkBrowser(){
100 this.ver=navigator.appVersion;
101 this.name=navigator.appName;
102 this.mac=(navigator.platform.toLowerCase().indexOf('mac')>-1)?true:false;
103 this.opera=(navigator.userAgent.toLowerCase().indexOf('opera')>-1)?true:false;
104 this.dom=document.getElementById?true:false;
105 this.ns=(this.name=='Netscape');
106 this.ie4=(document.all && !this.dom)?true:false;
107 this.ie=(this.name =='Microsoft Internet Explorer'&&!this.opera)?true:false;
108 this.ie5=(this.ie && (navigator.userAgent.indexOf("MSIE 5")!=-1))?true:false;
109 this.macie50=(this.mac&&this.ie5&&(navigator.userAgent.indexOf("MSIE 5.0")!=-1))?true:false
110 this.ns4=(this.ns && parseInt(this.ver) == 4)?true:false;
111 this.ns6=((this.name=="Netscape")&&(parseInt(this.ver)==5))?true:false
112 this.standards=document.getElementById?true:false;
113 this.dhtml=this.standards||this.ie4||this.ns4;
114 }
115
116 function showMe(eID){
117 myFloater=new makeLayerObj(eID)
118 myFloater.css.visibility="visible";
119 }
120
121 function hideMe(eID){
122 myFloater=new makeLayerObj(eID)
123 myFloater.css.visibility="hidden";
124 }