// ** jquery scroll to top control script-(c) Dynamic drive DHTML code library: http://www.dynamicdrive.com /.
// ** available/usage terms at http://www.dynamicdrive.com/(March 30th, 09')
// ** V1.1 (rjl 7th, 09 '):
// ** 1) adds ability to scroll to an absolute position (from top of page) or specific element on the page instead.
// ** 2) fixes scroll animation not working in opera.
VaR scrolltotop = {
// Startline: integer. number of pixels from top of DOC scrollbar is scrolled before showing control
// Scrollto: keyword (integer, or "scroll_to_element_id"). How far to scroll document up when control is clicked on (0 = Top ).
Setting: {Startline: 100, scrollto: 0, scrollduration: 1000, fadeduration: [500,100]},
Controlhtml: ' ', // html for control, which is auto wrapped in Div w/id = "topcontrol"
Controlattrs: {offsetx: 5, offsety: 5}, // offset of control relative to right/bottom of window corner
Anchorkeyword: '# top', // enter href value of HTML anchors on the page that shoshould also act as "scroll up" Links
State: {isvisible: false, shouldvisible: false },
scrollup: function () {
If (! This.css fixedsupport) // if control is positioned using JavaScript
this.20.control.css ({opacity: 0}) // hide control immediately after clicking it
var DEST = isnan (this. setting. scrollto )? This. setting. scrollto: parseint (this. setting. scrollto)
If (typeof DEST = "string" & jquery ('#' + DEST ). length = 1) // check element set by string exists
DEST = jquery ('#' + DEST ). offset (). top
else
DEST = 0
This. $ body. animate ({scrolltop: DEST}, this. setting. scrollduration);
},
Keepfixed: function (){
VaR $ window = jquery (window)
VaR controlx = $ window. scrollleft () + $ window. Width ()-this. $ control. Width ()-This. controlattrs. offsetx
VaR controly = $ window. scrolltop () + $ window. Height ()-this. $ control. Height ()-This. controlattrs. offsety
This.$control.css ({left: controlx + 'px ', top: controly + 'px '})
},
Togglecontrol: function (){
VaR scrolltop = jquery (window). scrolltop ()
If (! This.css fixedsupport)
This. keepfixed ()
This. state. shouldvisible = (scrolltop> = This. Setting. Startline )? True: false
If (this. state. shouldvisible &&! This. state. isvisible ){
This. $ control. Stop (). animate ({opacity: 1}, this. Setting. fadeduration [0])
This. state. isvisible = true
}
Else if (this. state. shouldvisible = false & this. state. isvisible ){
This. $ control. Stop (). animate ({opacity: 0}, this. Setting. fadeduration [1])
This. state. isvisible = false
}
},
Init: function (){
Jquery (document). Ready (function ($ ){
VaR mainobj = scrolltotop
VaR iebrws = Document. All
Mainobj.css fixedsupport =! Iebrws | iebrws & document. compatmode = "css1compat" & window. XMLHttpRequest // not IE or IE7 + browsers in standards mode
Mainobj. $ body = (window. Opera )? (Document. compatmode = "css1compat "? $ ('Html '): $ ('body'): $ ('html, body ')
Mainobj. $ control = $ ('<Div id = "topcontrol">' + mainobj. controlhtml + '</div> ')
. CSS ({position: mainobj.css fixedsupport? 'Fixed': 'absolute ', bottom: mainobj. controlattrs. offsety, right: mainobj. controlattrs. offsetx, opacity: 0, cursor: 'pointer '})
. ATTR ({Title: 'Return head '})
. Click (function () {mainobj. scrollup (); Return false })
. Appendto ('body ')
If (document. All &&! Window. XMLHttpRequest & mainobj. $ control. Text ()! = '') // Loose check for IE6 and below, plus whether control contains any text
Mainobj.20.control.css ({width: mainobj. $ control. Width ()}) // IE6-seems to require an explicit width on a div containing text
Mainobj. togglecontrol ()
$ ('A [href = "'+ mainobj. anchorkeyword +'"] '). Click (function (){
Mainobj. scrollup ()
Return false
})
$ (Window). BIND ('scroll resize', function (e ){
Mainobj. togglecontrol ()
})
})
}
}
Scrolltotop. INIT ()