window.onload = function() { textChanger.init(); }
var textChanger = { cpanel: 'resize-fonts', element: 'wrapper', defaultFS: 1, init: function() {
    var cpel = document.getElementById(textChanger.cpanel); var el = document.getElementById(textChanger.element); if (cpel == null || el == null) { alert('The elements with the \"' + textChanger.cpanel + '\" and/or \"' + textChanger.element + '\" ID do not exist in HTML source.'); } else {
        var u = document.createElement('ul'); cpel.appendChild(u); u.innerHTML = '<li id="decrease"><a href="#" title="Decrease font size">A</a></li>' + '<li id="reset"><a href="#" title="Default font size">A</a></li>' + '<li id="increase"><a href="#" title="Increase font size">A</a></li>'
        var sz = textChanger.getCookie(); el.style.fontSize = sz ? sz + 'em' : textChanger.defaultFS + 'em'; var incr = document.getElementById('increase'); incr.onclick = function() { textChanger.changeSize(1); return false; }; var decr = document.getElementById('decrease'); decr.onclick = function() { textChanger.changeSize(-1); return false; }; var reset = document.getElementById('reset'); reset.onclick = function() { textChanger.changeSize(0); return false; };
    } 
}, changeSize: function(val) {
    var el = document.getElementById(textChanger.element); var size = el.style.fontSize.substring(0, 3); var fSize = parseFloat(size, 10); if (val == 1) { fSize += 0.11; if (fSize > 2.0) fSize = 2.0; }
    if (val == -1) { fSize -= 0.11; if (fSize < 0.5) fSize = 0.5; }
    if (val == 0) { fSize = 1; }
    el.style.fontSize = fSize + 'em'; textChanger.updateCookie(fSize);
}, updateCookie: function(vl) { var today = new Date(); var exp = new Date(today.getTime() + (365 * 24 * 60 * 60 * 1000)); document.cookie = 'textChangerL=size=' + vl + ';' + 'expires=' + exp.toGMTString() + ';' + 'path=/'; }, getCookie: function() {
    var cname = 'textChangerL=size='; var start = document.cookie.indexOf(cname); var len = start + cname.length; if ((!start) && (cname != document.cookie.substring(0, cname.length))) { return null; }
    if (start == -1) return null; var end = document.cookie.indexOf(";", len); if (end == -1) end = document.cookie.length; return unescape(document.cookie.substring(len, end));
} 
}
$j(document).ready(function() {
    $j('.tabset').each(function(i, tabset) {
        var _tabLinks = $j('a.tab', tabset), _active; _tabLinks.each(function(j, link) {
            var _id = $j(link.href.substr(link.href.indexOf('#'))); if ($j(link).hasClass('active')) { _id.show(); _active = _id; }
            else _id.hide(); $j(link).click(function() { _tabLinks.removeClass('active'); _active.hide(); $j(link).addClass('active'); _id.show(); _active = _id; return false; })
        });
    });
}); jQuery.fn.tabSlide = function(_options) {
    var _options = jQuery.extend({ btPrev: 'a.prev', btNext: 'a.next', tabs: 'ul.tabset a', holderList: 'div', scrollElParent: 'ul', scrollEl: 'li', duration: 1000, autoSlide: false, startAfterClick: 10000, otherLinks: false, animateContentHeight: false }, _options)
    return this.each(function() {
        var _this = $j(this); var _holder = $j(_options.holderList, _this); var _mover = $j(_options.scrollElParent, _holder); var _scrollEl = $j(_options.scrollEl, _mover); var _next = $j(_options.btNext, _this); var _prev = $j(_options.btPrev, _this); var _tabs = $j(_options.tabs, _this); var _otherLinks = $j(_options.otherLinks, _this); var _margin = 0; var _duration = _options.duration; var _current = 0; var _step = _holder.innerWidth(); var _length = _scrollEl.length; var _afterTimer = false, _contentHeight, slideHeight = []; var _slideTimer = false; if (_options.autoSlide) _slideTimer = setInterval(function() { nextSlides() }, _options.autoSlide); _scrollEl.each(function(i, slide) { if (i == 0) _contentHeight = $j(slide).outerHeight(true); slideHeight[i] = $j(slide).outerHeight(true); }); if (_options.animateContentHeight)
            _holder.css({ 'overflow': 'hidden', 'height': _contentHeight }); if (_options.btNext) { _next.click(function() { checkAutoScroll(); nextSlides(); return false; }); }
        if (_options.btPrev) { _prev.click(function() { checkAutoScroll(); _current -= 1; if (_current < 0) _current = _length - 1; _margin = _step * _current; animateTab(); animateHeight(_current); setActive(); return false; }); }
        if (_options.tabs) {
            if (!_tabs.parent().filter('.active').length) { _tabs.eq(0).parent().addClass('active'); }
            _tabs.each(function(i, tabLink) {
                if ($j(tabLink).parent().hasClass('active')) {
                    _margin = _step * i; _mover.css({ 'marginLeft': -_margin })
                    _current = i;
                } 
            }); _tabs.click(function() { var i = _tabs.index(this); checkAutoScroll(); _tabs.parent().removeClass('active'); _margin = _step * i; animateTab(); animateHeight(i); _current = i; $j(this).parent().addClass('active'); return false; });
        }
        if (_options.otherLinks) { _otherLinks.click(function() { checkAutoScroll(); _current = parseInt(this.href.substr(this.href.indexOf('#') + 1)) - 1; _margin = _step * _current; animateTab(); animateHeight(_current); setActive(); return false; }); }
        function checkAutoScroll() { if (_slideTimer) clearInterval(_slideTimer); if (_afterTimer) clearTimeout(_afterTimer); if (_options.autoSlide && _options.startAfterClick) { _afterTimer = setTimeout(function() { _slideTimer = setInterval(function() { nextSlides() }, _options.autoSlide); }, _options.startAfterClick - _options.autoSlide) } }
        function nextSlides() { _current += 1; if (_current >= _length) _current = 0; _margin = _step * _current; setActive(); animateTab(); animateHeight(_current); return false; }
        function animateTab() { _mover.animate({ 'marginLeft': -_margin }, { duration: _duration, queue: false }); }
        function animateHeight(_index) { if (_options.animateContentHeight) { _holder.animate({ 'height': slideHeight[_index] }, { duration: _duration, queue: false }); } }
        function setActive() { if (_options.tabs) { _tabs.parent().removeClass('active'); _tabs.eq(_current).parent().addClass('active'); } } 
    });
}
$j(document).ready(function() {
    var _slideDuration = 300; var _li = $j('#nav li:has(div.drop-down)'); var _mainHome = $j('.homepage #main'); var _main = $j('#main'); var _homepage = true; if (_mainHome.length == 0) _homepage = false; _li.each(function(i, li) {
        var _drop = $j('div.drop-down', li); _drop.show(); var _h = _drop.outerHeight(); _drop.hide(); var _over, _out; $j(li).mouseenter(function() {
            if (_out) clearTimeout(_out); _over = setTimeout(function() {
                _drop.addClass('hover'); if (_homepage)
                    _mainHome.animate({ paddingTop: _h + 20 }, _slideDuration); else
                    _main.animate({ paddingTop: _h + 33 }, _slideDuration); _drop.slideDown(_slideDuration)
            }, 200)
        }).mouseleave(function() {
            if (_over) clearTimeout(_over); _out = setTimeout(function() {
                if (_homepage)
                    _mainHome.animate({ paddingTop: 20 }, _slideDuration); else
                    _main.animate({ paddingTop: 33 }, _slideDuration); _drop.slideUp(_slideDuration, function() { _drop.removeClass('hover'); })
            }, 50);
        });
    }); 
    var galleryTabs = $j('div.gallery').find('li').size();
    var randomTabIndex = Math.floor((galleryTabs+1)*Math.random());
    $j('div.gallery').find('li').eq(randomTabIndex).addClass('active');
    if (typeof $j().tabSlide == 'function') { $j('div.gallery').tabSlide({ btPrev: 'a.link-prev', btNext: 'a.link-next', tabs: 'ul.switcher a:not([class*=link])', holderList: '> div', scrollElParent: '> ul', scrollEl: '> li', duration: 1000, autoSlide: 8000, startAfterClick: 10000, otherLinks: false, animateContentHeight: false }); } 
});
