﻿$(document).ready(function () {

    // Main Nav Dropdown
    function menuAnimateIn() {
        var ol = $(this).children("ol");
        ol.animate({ height: "show", opacity: 1 }, { duration: 100 });

        $(this).children("a").addClass('hovering');
    };

    function menuAnimateOut() {
        var ol = $(this).children("ol");
        ol.animate({ height: "hide", opacity: 0 }, { duration: 100 });

        $(this).children("a").removeClass('hovering');
    };

    $("ol#header_main_nav li").hoverIntent({ over: menuAnimateIn, timeout: 150, out: menuAnimateOut });


    // FORMS
    // hide input initial value
    $('.default-value').each(function () {
        var default_value = this.value;
        $(this).focus(function () {
            $(this).addClass('has-focus');
            if (this.value == default_value) {
                this.value = '';
            }
        });
        $(this).blur(function () {
            $(this).removeClass('has-focus');
            if (this.value == '') {
                this.value = default_value;
            }
        });
    });


    // if there is a scroller present, initialize it, get/set heights
    if ($('#scrollbar1').length) { // implies *not* zero
        $('#scrollbar1').tinyscrollbar({ sizethumb: 50 });
    }

    resizeLeftColumn();

    $(window).resize(function () {
        clearTimeout(this.id);
        this.id = setTimeout(resizeLeftColumn, 250);
    });

    function resizeLeftColumn() {
        var windowheight = $(window).height();

        var columnheight = (windowheight - 212) + 'px'; //62px is height of footer, 150px height of header
        $('#content_left').css({ 'height': columnheight });

        if ($('#scrollbar1').length) {
            var viewportheight = (windowheight - 212) - 60 + 'px'; // 60px is the amount of padding above and below the scroller
            $('#scrollbar1 .viewport').css({ 'height': viewportheight });

            var adjustedviewportheight = (windowheight - 212) - 120 + 'px'; // 120px is padding above/below scroller + height of inpage title
            $('#content_right #scrollbar1 .viewport').css({ 'height': adjustedviewportheight });

            updateScroller();
        }

    };

    function updateScroller() {
        var oScrollbar = $('#scrollbar1');
        oScrollbar.tinyscrollbar({ sizethumb: 50 });
        oScrollbar.tinyscrollbar_update();
    };




    // tiny Carousels
    $('#slider-code').tinycarousel({
        controls: false,
        duration: 500,
        interval: true,
        intervaltime: 5000,
        axis: 'y'
    });
    $('#slider-code1').tinycarousel({
        controls: false,
        duration: 500,
        interval: true,
        intervaltime: 30000,
        axis: 'y'
    });$('#slider-code2').tinycarousel({
        controls: false,
        duration: 500,
        interval: true,
        intervaltime: 30000,
        axis: 'y'
    });


    // Size/Spec Chart on Product Page
    $('#sizechart_table').css('height', $('#sizechart_table').height() + 'px').hide();
    
    $('#sizechart').click(function () {
        $('#sizechart_table').slideToggle('fast', function () {
            
            var spantxt = $('#sizechart span').html();
            if (spantxt == '[ close ]') {
                $('#sizechart span').html('click here');
            } else {
                $('#sizechart span').html('[ close ]');
            }

        });
    });


});
/*** hoverIntent r6 // 2011.02.26 // jQuery 1.5.1+* <http://cherne.net/brian/resources/jquery.hoverIntent.html>* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne brian(at)cherne(dot)net
*/
(function ($) { $.fn.hoverIntent = function (f, g) { var cfg = { sensitivity: 7, interval: 100, timeout: 0 }; cfg = $.extend(cfg, g ? { over: f, out: g} : f); var cX, cY, pX, pY; var track = function (ev) { cX = ev.pageX; cY = ev.pageY }; var compare = function (ev, ob) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); if ((Math.abs(pX - cX) + Math.abs(pY - cY)) < cfg.sensitivity) { $(ob).unbind("mousemove", track); ob.hoverIntent_s = 1; return cfg.over.apply(ob, [ev]) } else { pX = cX; pY = cY; ob.hoverIntent_t = setTimeout(function () { compare(ev, ob) }, cfg.interval) } }; var delay = function (ev, ob) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t); ob.hoverIntent_s = 0; return cfg.out.apply(ob, [ev]) }; var handleHover = function (e) { var ev = jQuery.extend({}, e); var ob = this; if (ob.hoverIntent_t) { ob.hoverIntent_t = clearTimeout(ob.hoverIntent_t) } if (e.type == "mouseenter") { pX = ev.pageX; pY = ev.pageY; $(ob).bind("mousemove", track); if (ob.hoverIntent_s != 1) { ob.hoverIntent_t = setTimeout(function () { compare(ev, ob) }, cfg.interval) } } else { $(ob).unbind("mousemove", track); if (ob.hoverIntent_s == 1) { ob.hoverIntent_t = setTimeout(function () { delay(ev, ob) }, cfg.timeout) } } }; return this.bind('mouseenter', handleHover).bind('mouseleave', handleHover) } })(jQuery);

//TINY SCROLLER
(function ($) {
    $.tiny = $.tiny || {}; $.tiny.scrollbar = { options: { axis: 'y', wheel: 40, scroll: true, size: 'auto', sizethumb: 'auto'} }; $.fn.tinyscrollbar = function (options) { var options = $.extend({}, $.tiny.scrollbar.options, options); this.each(function () { $(this).data('tsb', new Scrollbar($(this), options)); }); return this; }; $.fn.tinyscrollbar_update = function (sScroll) { return $(this).data('tsb').update(sScroll); }; function Scrollbar(root, options) {
        var oSelf = this; var oWrapper = root; var oViewport = { obj: $('.viewport', root) }; var oContent = { obj: $('.overview', root) }; var oScrollbar = { obj: $('.scrollbar', root) }; var oTrack = { obj: $('.track', oScrollbar.obj) }; var oThumb = { obj: $('.thumb', oScrollbar.obj) }; var sAxis = options.axis == 'x', sDirection = sAxis ? 'left' : 'top', sSize = sAxis ? 'Width' : 'Height'; var iScroll, iPosition = { start: 0, now: 0 }, iMouse = {}; function initialize() { oSelf.update(); setEvents(); return oSelf; }
        this.update = function (sScroll) { oViewport[options.axis] = oViewport.obj[0]['offset' + sSize]; oContent[options.axis] = oContent.obj[0]['scroll' + sSize]; oContent.ratio = oViewport[options.axis] / oContent[options.axis]; oScrollbar.obj.toggleClass('disable', oContent.ratio >= 1); oTrack[options.axis] = options.size == 'auto' ? oViewport[options.axis] : options.size; oThumb[options.axis] = Math.min(oTrack[options.axis], Math.max(0, (options.sizethumb == 'auto' ? (oTrack[options.axis] * oContent.ratio) : options.sizethumb))); oScrollbar.ratio = options.sizethumb == 'auto' ? (oContent[options.axis] / oTrack[options.axis]) : (oContent[options.axis] - oViewport[options.axis]) / (oTrack[options.axis] - oThumb[options.axis]); iScroll = (sScroll == 'relative' && oContent.ratio <= 1) ? Math.min((oContent[options.axis] - oViewport[options.axis]), Math.max(0, iScroll)) : 0; iScroll = (sScroll == 'bottom' && oContent.ratio <= 1) ? (oContent[options.axis] - oViewport[options.axis]) : isNaN(parseInt(sScroll)) ? iScroll : parseInt(sScroll); setSize(); }; function setSize() { oThumb.obj.css(sDirection, iScroll / oScrollbar.ratio); oContent.obj.css(sDirection, -iScroll); iMouse['start'] = oThumb.obj.offset()[sDirection]; var sCssSize = sSize.toLowerCase(); oScrollbar.obj.css(sCssSize, oTrack[options.axis]); oTrack.obj.css(sCssSize, oTrack[options.axis]); oThumb.obj.css(sCssSize, oThumb[options.axis]); }; function setEvents() {
            oThumb.obj.bind('mousedown', start); oThumb.obj[0].ontouchstart = function (oEvent) { oEvent.preventDefault(); oThumb.obj.unbind('mousedown'); start(oEvent.touches[0]); return false; }; oTrack.obj.bind('mouseup', drag); if (options.scroll && this.addEventListener) { oWrapper[0].addEventListener('DOMMouseScroll', wheel, false); oWrapper[0].addEventListener('mousewheel', wheel, false); }
            else if (options.scroll) { oWrapper[0].onmousewheel = wheel; } 
        }; function start(oEvent) { iMouse.start = sAxis ? oEvent.pageX : oEvent.pageY; var oThumbDir = parseInt(oThumb.obj.css(sDirection)); iPosition.start = oThumbDir == 'auto' ? 0 : oThumbDir; $(document).bind('mousemove', drag); document.ontouchmove = function (oEvent) { $(document).unbind('mousemove'); drag(oEvent.touches[0]); }; $(document).bind('mouseup', end); oThumb.obj.bind('mouseup', end); oThumb.obj[0].ontouchend = document.ontouchend = function (oEvent) { $(document).unbind('mouseup'); oThumb.obj.unbind('mouseup'); end(oEvent.touches[0]); }; return false; }; function wheel(oEvent) { if (!(oContent.ratio >= 1)) { oEvent = $.event.fix(oEvent || window.event); var iDelta = oEvent.wheelDelta ? oEvent.wheelDelta / 120 : -oEvent.detail / 3; iScroll -= iDelta * options.wheel; iScroll = Math.min((oContent[options.axis] - oViewport[options.axis]), Math.max(0, iScroll)); oThumb.obj.css(sDirection, iScroll / oScrollbar.ratio); oContent.obj.css(sDirection, -iScroll); oEvent.preventDefault(); }; }; function end(oEvent) { $(document).unbind('mousemove', drag); $(document).unbind('mouseup', end); oThumb.obj.unbind('mouseup', end); document.ontouchmove = oThumb.obj[0].ontouchend = document.ontouchend = null; return false; }; function drag(oEvent) {
            if (!(oContent.ratio >= 1)) { iPosition.now = Math.min((oTrack[options.axis] - oThumb[options.axis]), Math.max(0, (iPosition.start + ((sAxis ? oEvent.pageX : oEvent.pageY) - iMouse.start)))); iScroll = iPosition.now * oScrollbar.ratio; oContent.obj.css(sDirection, -iScroll); oThumb.obj.css(sDirection, iPosition.now); }
            return false;
        }; return initialize();
    };
})(jQuery);

// TINY CAROUSEL
(function ($) { $.tiny = $.tiny || {}; $.tiny.carousel = { options: { start: 1, display: 1, axis: 'x', controls: true, pager: false, interval: false, intervaltime: 3000, rewind: false, animation: true, duration: 1000, callback: null} }; $.fn.tinycarousel = function (options) { var options = $.extend({}, $.tiny.carousel.options, options); this.each(function () { $(this).data('tcl', new Carousel($(this), options)); }); return this; }; $.fn.tinycarousel_start = function () { $(this).data('tcl').start(); }; $.fn.tinycarousel_stop = function () { $(this).data('tcl').stop(); }; $.fn.tinycarousel_move = function (iNum) { $(this).data('tcl').move(iNum - 1, true); }; function Carousel(root, options) { var oSelf = this; var oViewport = $('.viewport:first', root); var oContent = $('.overview:first', root); var oPages = oContent.children(); var oBtnNext = $('.next:first', root); var oBtnPrev = $('.prev:first', root); var oPager = $('.pager:first', root); var iPageSize, iSteps, iCurrent, oTimer, bPause, bForward = true, bAxis = options.axis == 'x'; function initialize() { iPageSize = bAxis ? $(oPages[0]).outerWidth(true) : $(oPages[0]).outerHeight(true); var iLeftover = Math.ceil(((bAxis ? oViewport.outerWidth() : oViewport.outerHeight()) / (iPageSize * options.display)) - 1); iSteps = Math.max(1, Math.ceil(oPages.length / options.display) - iLeftover); iCurrent = Math.min(iSteps, Math.max(1, options.start)) - 2; oContent.css(bAxis ? 'width' : 'height', (iPageSize * oPages.length)); oSelf.move(1); setEvents(); return oSelf; }; function setEvents() { if (options.controls && oBtnPrev.length > 0 && oBtnNext.length > 0) { oBtnPrev.click(function () { oSelf.move(-1); return false; }); oBtnNext.click(function () { oSelf.move(1); return false; }); } if (options.interval) { root.hover(oSelf.stop, oSelf.start); } if (options.pager && oPager.length > 0) { $('a', oPager).click(setPager); } }; function setButtons() { if (options.controls) { oBtnPrev.toggleClass('disable', !(iCurrent > 0)); oBtnNext.toggleClass('disable', !(iCurrent + 1 < iSteps)); } if (options.pager) { var oNumbers = $('.pagenum', oPager); oNumbers.removeClass('active'); $(oNumbers[iCurrent]).addClass('active'); } }; function setPager(oEvent) { if ($(this).hasClass('pagenum')) { oSelf.move(parseInt(this.rel), true); } return false; }; function setTimer() { if (options.interval && !bPause) { clearTimeout(oTimer); oTimer = setTimeout(function () { iCurrent = iCurrent + 1 == iSteps ? -1 : iCurrent; bForward = iCurrent + 1 == iSteps ? false : iCurrent == 0 ? true : bForward; oSelf.move(bForward ? 1 : -1); }, options.intervaltime); } }; this.stop = function () { clearTimeout(oTimer); bPause = true; }; this.start = function () { bPause = false; setTimer(); }; this.move = function (iDirection, bPublic) { iCurrent = bPublic ? iDirection : iCurrent += iDirection; if (iCurrent > -1 && iCurrent < iSteps) { var oPosition = {}; oPosition[bAxis ? 'left' : 'top'] = -(iCurrent * (iPageSize * options.display)); oContent.animate(oPosition, { queue: false, duration: options.animation ? options.duration : 0, complete: function () { if (typeof options.callback == 'function') options.callback.call(this, oPages[iCurrent], iCurrent); } }); setButtons(); setTimer(); } }; return initialize(); }; })(jQuery);


