2 // X v3.14.1, Cross-Browser DHTML Library from Cross-Browser.com
3 // Copyright (c) 2002,2003 Michael Foster (mike@cross-browser.com)
4 // This library is distributed under the terms of the LGPL (gnu.org)
7 var xVersion
='3.14.1',xOp7
=false,xOp5or6
=false,xIE4Up
=false,xNN4
=false,xUA
=navigator
.userAgent
.toLowerCase();
9 xOp7
=(xUA
.indexOf('opera 7')!=-1 || xUA
.indexOf('opera/7')!=-1);
10 if (!xOp7
) xOp5or6
=(xUA
.indexOf('opera 5')!=-1 || xUA
.indexOf('opera/5')!=-1 || xUA
.indexOf('opera 6')!=-1 || xUA
.indexOf('opera/6')!=-1);
12 else if(document
.layers
) {xNN4
=true;}
13 else {xIE4Up
=document
.all
&& xUA
.indexOf('msie')!=-1 && parseInt(navigator
.appVersion
)>=4;}
15 function xGetElementById(e
) {
16 if(typeof(e
)!='string') return e
;
17 if(document
.getElementById
) e
=document
.getElementById(e
);
18 else if(document
.all
) e
=document
.all
[e
];
19 else if(document
.layers
) e
=xLayer(e
);
23 function xParent(e
,bNode
){
24 if (!(e
=xGetElementById(e
))) return null;
26 if (!bNode
&& xDef(e
.offsetParent
)) p
=e
.offsetParent
;
27 else if (xDef(e
.parentNode
)) p
=e
.parentNode
;
28 else if (xDef(e
.parentElement
)) p
=e
.parentElement
;
29 else if (xDef(e
.parentLayer
)){if (e
.parentLayer
!=window
) p
=e
.parentLayer
;}
33 for(var i
=0; i
<arguments
.length
; ++i
){if(typeof(arguments
[i
])=='undefined') return false;}
37 return typeof(s
)=='string';
40 return typeof(n
)=='number';
44 if(!(e
=xGetElementById(e
))) return;
45 if(e
.style
&& xDef(e
.style
.visibility
)) e
.style
.visibility
='visible';
46 else if(xDef(e
.visibility
)) e
.visibility
='show';
49 if(!(e
=xGetElementById(e
))) return;
50 if(e
.style
&& xDef(e
.style
.visibility
)) e
.style
.visibility
='hidden';
51 else if(xDef(e
.visibility
)) e
.visibility
='hide';
53 function xZIndex(e
,uZ
) {
54 if(!(e
=xGetElementById(e
))) return 0;
55 if(e
.style
&& xDef(e
.style
.zIndex
)) {
56 if(xNum(uZ
)) e
.style
.zIndex
=uZ
;
57 uZ
=parseInt(e
.style
.zIndex
);
59 else if(xDef(e
.zIndex
)) {
60 if(xNum(uZ
)) e
.zIndex
=uZ
;
65 function xColor(e
,sColor
) {
66 if(!(e
=xGetElementById(e
))) return '';
68 if(e
.style
&& xDef(e
.style
.color
)) {
69 if(xStr(sColor
)) e
.style
.color
=sColor
;
74 function xBackground(e
,sColor
,sImage
) {
75 if(!(e
=xGetElementById(e
))) return '';
79 if(!xOp5or6
) e
.style
.backgroundColor
=sColor
;
80 else e
.style
.background
=sColor
;
82 if(xStr(sImage
)) e
.style
.backgroundImage
=(sImage
!='')? 'url('+sImage
+')' : null;
83 if(!xOp5or6
) bg
=e
.style
.backgroundColor
;
84 else bg
=e
.style
.background
;
86 else if(xDef(e
.bgColor
)) {
87 if(xStr(sColor
)) e
.bgColor
=sColor
;
89 if(xStr(sImage
)) e
.background
.src
=sImage
;
94 function xMoveTo(e
,iX
,iY
) {
98 function xLeft(e
,iX
) {
99 if(!(e
=xGetElementById(e
))) return 0;
100 var css
=xDef(e
.style
);
101 if (css
&& xStr(e
.style
.left
)) {
102 if(xNum(iX
)) e
.style
.left
=iX
+'px';
104 iX
=parseInt(e
.style
.left
);
108 else if(css
&& xDef(e
.style
.pixelLeft
)) {
109 if(xNum(iX
)) e
.style
.pixelLeft
=iX
;
110 else iX
=e
.style
.pixelLeft
;
112 else if(xDef(e
.left
)) {
113 if(xNum(iX
)) e
.left
=iX
;
118 function xTop(e
,iY
) {
119 if(!(e
=xGetElementById(e
))) return 0;
120 var css
=xDef(e
.style
);
121 if(css
&& xStr(e
.style
.top
)) {
122 if(xNum(iY
)) e
.style
.top
=iY
+'px';
124 iY
=parseInt(e
.style
.top
);
128 else if(css
&& xDef(e
.style
.pixelTop
)) {
129 if(xNum(iY
)) e
.style
.pixelTop
=iY
;
130 else iY
=e
.style
.pixelTop
;
132 else if(xDef(e
.top
)) {
133 if(xNum(iY
)) e
.top
=iY
;
139 if (!(e
=xGetElementById(e
))) return 0;
140 if (xDef(e
.pageX
)) return e
.pageX
;
143 if (xDef(e
.offsetLeft
)) x
+= e
.offsetLeft
;
144 e
= xDef(e
.offsetParent
) ? e
.offsetParent
: null;
149 if (!(e
=xGetElementById(e
))) return 0;
150 if (xDef(e
.pageY
)) return e
.pageY
;
153 if (xDef(e
.offsetTop
)) y
+= e
.offsetTop
;
154 e
= xDef(e
.offsetParent
) ? e
.offsetParent
: null;
156 // if (xOp7) return y - document.body.offsetTop; // v3.14, temporary hack for opera bug 130324
159 function xOffsetLeft(e
) { // v3.14, see x_nn4.js
160 if (!(e
=xGetElementById(e
))) return 0;
161 if (xDef(e
.offsetLeft
)) return e
.offsetLeft
;
164 function xOffsetTop(e
) {
165 if (!(e
=xGetElementById(e
))) return 0;
166 if (xDef(e
.offsetTop
)) return e
.offsetTop
;
169 function xScrollLeft(e
) {
171 if (!(e
=xGetElementById(e
))) {
172 if(xDef(window
.pageXOffset
)) offset
=window
.pageXOffset
;
173 else if(document
.documentElement
&& document
.documentElement
.scrollLeft
) offset
=document
.documentElement
.scrollLeft
;
174 else if(document
.body
&& xDef(document
.body
.scrollLeft
)) offset
=document
.body
.scrollLeft
;
176 else { if (xNum(e
.scrollLeft
)) offset
= e
.scrollLeft
; }
179 function xScrollTop(e
) {
181 if (!(e
=xGetElementById(e
))) {
182 if(xDef(window
.pageYOffset
)) offset
=window
.pageYOffset
;
183 else if(document
.documentElement
&& document
.documentElement
.scrollTop
) offset
=document
.documentElement
.scrollTop
;
184 else if(document
.body
&& xDef(document
.body
.scrollTop
)) offset
=document
.body
.scrollTop
;
186 else { if (xNum(e
.scrollTop
)) offset
= e
.scrollTop
; }
190 function xResizeTo(e
,uW
,uH
) {
194 function xWidth(e
,uW
) {
195 if(!(e
=xGetElementById(e
))) return 0;
196 if (xNum(uW
)) { // v3.13.1
198 else uW
=Math
.round(uW
);
201 var css
=xDef(e
.style
);
202 if(css
&& xDef(e
.offsetWidth
) && xStr(e
.style
.width
)) {
203 if(uW
) xSetCW(e
, uW
);
206 else if(css
&& xDef(e
.style
.pixelWidth
)) {
207 if(uW
) e
.style
.pixelWidth
=uW
;
208 uW
=e
.style
.pixelWidth
;
210 else if(xDef(e
.clip
) && xDef(e
.clip
.right
)) {
211 if(uW
) e
.clip
.right
=uW
;
216 function xHeight(e
,uH
) {
217 if(!(e
=xGetElementById(e
))) return 0;
218 if (xNum(uH
)) { // v3.13.1
220 else uH
=Math
.round(uH
);
223 var css
=xDef(e
.style
);
224 if(css
&& xDef(e
.offsetHeight
) && xStr(e
.style
.height
)) {
225 if(uH
) xSetCH(e
, uH
);
228 else if(css
&& xDef(e
.style
.pixelHeight
)) {
229 if(uH
) e
.style
.pixelHeight
=uH
;
230 uH
=e
.style
.pixelHeight
;
232 else if(xDef(e
.clip
) && xDef(e
.clip
.bottom
)) {
233 if(uH
) e
.clip
.bottom
=uH
;
238 function xGetCS(ele
,sP
){return parseInt(document
.defaultView
.getComputedStyle(ele
,'').getPropertyValue(sP
));}
239 function xSetCW(ele
,uW
){
240 var pl
=0,pr
=0,bl
=0,br
=0;
241 if(xDef(document
.defaultView
) && xDef(document
.defaultView
.getComputedStyle
)){
242 pl
=xGetCS(ele
,'padding-left');
243 pr
=xGetCS(ele
,'padding-right');
244 bl
=xGetCS(ele
,'border-left-width');
245 br
=xGetCS(ele
,'border-right-width');
247 else if(xDef(ele
.currentStyle
,document
.compatMode
)){
248 if(document
.compatMode
=='CSS1Compat'){
249 pl
=parseInt(ele
.currentStyle
.paddingLeft
);
250 pr
=parseInt(ele
.currentStyle
.paddingRight
);
251 bl
=parseInt(ele
.currentStyle
.borderLeftWidth
);
252 br
=parseInt(ele
.currentStyle
.borderRightWidth
);
255 else if(xDef(ele
.offsetWidth
,ele
.style
.width
)){ // ?
256 ele
.style
.width
=uW
+'px';
257 pl
=ele
.offsetWidth
-uW
;
259 if(isNaN(pl
)) pl
=0; if(isNaN(pr
)) pr
=0; if(isNaN(bl
)) bl
=0; if(isNaN(br
)) br
=0;
260 var cssW
=uW
-(pl
+pr
+bl
+br
);
261 if(isNaN(cssW
)||cssW
<0) return;
262 else ele
.style
.width
=cssW
+'px';
264 function xSetCH(ele
,uH
){
265 var pt
=0,pb
=0,bt
=0,bb
=0;
266 if(xDef(document
.defaultView
) && xDef(document
.defaultView
.getComputedStyle
)){
267 pt
=xGetCS(ele
,'padding-top');
268 pb
=xGetCS(ele
,'padding-bottom');
269 bt
=xGetCS(ele
,'border-top-width');
270 bb
=xGetCS(ele
,'border-bottom-width');
272 else if(xDef(ele
.currentStyle
,document
.compatMode
)){
273 if(document
.compatMode
=='CSS1Compat'){
274 pt
=parseInt(ele
.currentStyle
.paddingTop
);
275 pb
=parseInt(ele
.currentStyle
.paddingBottom
);
276 bt
=parseInt(ele
.currentStyle
.borderTopWidth
);
277 bb
=parseInt(ele
.currentStyle
.borderBottomWidth
);
280 else if(xDef(ele
.offsetHeight
,ele
.style
.height
)){ // ?
281 ele
.style
.height
=uH
+'px';
282 pt
=ele
.offsetHeight
-uH
;
284 if(isNaN(pt
)) pt
=0; if(isNaN(pb
)) pb
=0; if(isNaN(bt
)) bt
=0; if(isNaN(bb
)) bb
=0;
285 var cssH
=uH
-(pt
+pb
+bt
+bb
);
286 if(isNaN(cssH
)||cssH
<0) return;
287 else ele
.style
.height
=cssH
+'px';
289 function xClip(e
,iTop
,iRight
,iBottom
,iLeft
) {
290 if(!(e
=xGetElementById(e
))) return;
292 if (xNum(iLeft
)) e
.style
.clip
='rect('+iTop
+'px '+iRight
+'px '+iBottom
+'px '+iLeft
+'px)';
293 else e
.style
.clip
='rect(0 '+parseInt(e
.style
.width
)+'px '+parseInt(e
.style
.height
)+'px 0)';
296 if (xNum(iLeft
)) { e
.clip
.top
=iTop
; e
.clip
.right
=iRight
; e
.clip
.bottom
=iBottom
; e
.clip
.left
=iLeft
; }
297 else { e
.clip
.top
=0; e
.clip
.right
=xWidth(e
); e
.clip
.bottom
=xHeight(e
); e
.clip
.left
=0; }
301 function xClientWidth() {
303 if(xOp5or6
) w
=window
.innerWidth
;
304 else if(!window
.opera
&& document
.documentElement
&& document
.documentElement
.clientWidth
) // v3.12
305 w
=document
.documentElement
.clientWidth
;
306 else if(document
.body
&& document
.body
.clientWidth
)
307 w
=document
.body
.clientWidth
;
308 else if(xDef(window
.innerWidth
,window
.innerHeight
,document
.height
)) {
310 if(document
.height
>window
.innerHeight
) w
-=16;
314 function xClientHeight() {
316 if(xOp5or6
) h
=window
.innerHeight
;
317 else if(!window
.opera
&& document
.documentElement
&& document
.documentElement
.clientHeight
) // v3.12
318 h
=document
.documentElement
.clientHeight
;
319 else if(document
.body
&& document
.body
.clientHeight
)
320 h
=document
.body
.clientHeight
;
321 else if(xDef(window
.innerWidth
,window
.innerHeight
,document
.width
)) {
322 h
=window
.innerHeight
;
323 if(document
.width
>window
.innerWidth
) h
-=16;
328 function xSlideTo(e
,x
,y
,uTime
) {
329 if (!(e
=xGetElementById(e
))) return;
330 if (!e
.timeout
) e
.timeout
= 25;
331 e
.xTarget
= x
; e
.yTarget
= y
; e
.slideTime
= uTime
; e
.stop
= false;
332 e
.yA
= e
.yTarget
- xTop(e
); e
.xA
= e
.xTarget
- xLeft(e
); // A = distance
333 e
.B
= Math
.PI
/ (2 * e
.slideTime
); // B = period
334 e
.yD
= xTop(e
); e
.xD
= xLeft(e
); // D = initial position
335 var d
= new Date(); e
.C
= d
.getTime();
336 if (!e
.moving
) xSlide(e
);
339 if (!(e
=xGetElementById(e
))) return;
340 var now
, s
, t
, newY
, newX
;
342 t
= now
.getTime() - e
.C
;
343 if (e
.stop
) { e
.moving
= false; }
344 else if (t
< e
.slideTime
) {
345 setTimeout("xSlide('"+e
.id
+"')", e
.timeout
);
346 s
= Math
.sin(e
.B
* t
);
347 newX
= Math
.round(e
.xA
* s
+ e
.xD
);
348 newY
= Math
.round(e
.yA
* s
+ e
.yD
);
349 xMoveTo(e
, newX
, newY
);
353 xMoveTo(e
, e
.xTarget
, e
.yTarget
);
358 function xAddEventListener(e
,eventType
,eventListener
,useCapture
) {
359 if(!(e
=xGetElementById(e
))) return;
360 eventType
=eventType
.toLowerCase();
361 if((!xIE4Up
&& !xOp7
) && e
==window
) {
362 if(eventType
=='resize') { window
.xPCW
=xClientWidth(); window
.xPCH
=xClientHeight(); window
.xREL
=eventListener
; xResizeEvent(); return; }
363 if(eventType
=='scroll') { window
.xPSL
=xScrollLeft(); window
.xPST
=xScrollTop(); window
.xSEL
=eventListener
; xScrollEvent(); return; }
365 var eh
='e.on'+eventType
+'=eventListener';
366 if(e
.addEventListener
) e
.addEventListener(eventType
,eventListener
,useCapture
);
367 else if(e
.attachEvent
) e
.attachEvent('on'+eventType
,eventListener
);
368 else if(e
.captureEvents
) {
369 if(useCapture
||(eventType
.indexOf('mousemove')!=-1)) { e
.captureEvents(eval('Event.'+eventType
.toUpperCase())); }
374 function xRemoveEventListener(e
,eventType
,eventListener
,useCapture
) {
375 if(!(e
=xGetElementById(e
))) return;
376 eventType
=eventType
.toLowerCase();
377 if((!xIE4Up
&& !xOp7
) && e
==window
) {
378 if(eventType
=='resize') { window
.xREL
=null; return; }
379 if(eventType
=='scroll') { window
.xSEL
=null; return; }
381 var eh
='e.on'+eventType
+'=null';
382 if(e
.removeEventListener
) e
.removeEventListener(eventType
,eventListener
,useCapture
);
383 else if(e
.detachEvent
) e
.detachEvent('on'+eventType
,eventListener
);
384 else if(e
.releaseEvents
) {
385 if(useCapture
||(eventType
.indexOf('mousemove')!=-1)) { e
.releaseEvents(eval('Event.'+eventType
.toUpperCase())); }
390 function xEvent(evt
) { // cross-browser event object prototype
398 var e
= evt
? evt
: window
.event
;
400 if(e
.type
) this.type
= e
.type
;
401 if(e
.target
) this.target
= e
.target
;
402 else if(e
.srcElement
) this.target
= e
.srcElement
;
403 else if(xNN4
) this.target
= xLayerFromPoint(e
.pageX
, e
.pageY
);
404 if(xOp5or6
) { this.pageX
= e
.clientX
; this.pageY
= e
.clientY
; }
405 else if(xDef(e
.pageX
,e
.pageY
)) { this.pageX
= e
.pageX
; this.pageY
= e
.pageY
; } // v3.14
406 else if(xDef(e
.clientX
,e
.clientY
)) { this.pageX
= e
.clientX
+ xScrollLeft(); this.pageY
= e
.clientY
+ xScrollTop(); }
407 if(xDef(e
.offsetX
,e
.offsetY
)) { this.offsetX
= e
.offsetX
; this.offsetY
= e
.offsetY
; }
408 else if(xDef(e
.layerX
,e
.layerY
)) { this.offsetX
= e
.layerX
; this.offsetY
= e
.layerY
; }
409 else { this.offsetX
= this.pageX
- xPageX(this.target
); this.offsetY
= this.pageY
- xPageY(this.target
); }
410 if (e
.keyCode
) { this.keyCode
= e
.keyCode
; } // for moz/fb, if keyCode==0 use which
411 else if (xDef(e
.which
)) { this.keyCode
= e
.which
; }
413 function xResizeEvent() { // window resize event simulation
414 if (window
.xREL
) setTimeout('xResizeEvent()', 250);
415 var cw
= xClientWidth(), ch
= xClientHeight();
416 if (window
.xPCW
!= cw
|| window
.xPCH
!= ch
) { window
.xPCW
= cw
; window
.xPCH
= ch
; if (window
.xREL
) window
.xREL(); }
418 function xScrollEvent() { // window scroll event simulation
419 if (window
.xSEL
) setTimeout('xScrollEvent()', 250);
420 var sl
= xScrollLeft(), st
= xScrollTop();
421 if (window
.xPSL
!= sl
|| window
.xPST
!= st
) { window
.xPSL
= sl
; window
.xPST
= st
; if (window
.xSEL
) window
.xSEL(); }