﻿(function($) {
    jQuery.fn.countDown = function(o) {
        if ($(this).length == 0) { return false; }
        o = $.extend({
            countTime: 10000,
            displayFormat: "%%H%% %%M%% %%S%%",
            countActive: true,
            countStepper: -1,
            leadingZero: true,
            useId: true,
            pollTime: false,
            pollFrequency: 30,
            finishFunction: function() { }
        }, o || {});


        CountStepper = Math.ceil(o.countStepper);
        DisplayFormat = o.displayFormat;
        LeadingZero = o.leadingZero;
        CountActive = o.countActive;
        CountTime = o.countTime;
        UseId = o.useId;
        PollTime = o.pollTime;
        PollFrequency = o.pollFrequency;
        finishFunction = o.finishFunction;
        Elements = this;
        SetTimeOutPeriod = (Math.abs(CountStepper) - 1) * 1000 + 990;
        $.fn.countDown.CountBack(o.countTime);
    }

    function calcage(secs, num1, num2, id) {
        s = ((Math.floor(secs / num1)) % num2).toString();
        if ((LeadingZero && s.length < 2) || (id == "s" && s.length < 2))
            s = "0" + s;
        if (UseId) {
            return '<span id="' + id + '">' + s + '</span>';
        } else {
            return '<span>' + s + '</span>';
        }
    }

    $.fn.countDown.CountBack = function(secs) {
        if (secs < 0) {
            $('#cntdwn').hide();
            $('#starts').html('This collection is on sale now.').css("right", "20px");
            finishFunction.call(this);
            return;
        } else if (secs <= CountTime) {
            
        }
        //DisplayStr = DisplayFormat.replace(/%%D%%/g, calcage(secs,86400,100000, "d"));
        DisplayStr = DisplayFormat.replace(/%%H%%/g, calcage(secs, 3600, 48, "h"));
        DisplayStr = DisplayStr.replace(/%%M%%/g, calcage(secs, 60, 60, "m"));
        DisplayStr = DisplayStr.replace(/%%S%%/g, calcage(secs, 1, 60, "s"));
        $(Elements).html(DisplayStr);
        if (CountActive)
            setTimeout("$.fn.countDown.CountBack(" + (secs + CountStepper) + ")", SetTimeOutPeriod);
    }
})(jQuery);

var int = 0;

(function($) {
    // Compliant with jquery.noConflict()
    $.fn.jCarouselLite = function(o) {
        o = $.extend({
            btnPrev: null,
            btnNext: null,
            btnGo: null,
            curInd: null,
            mouseWheel: false,
            auto: null,

            speed: 200,
            easing: null,

            vertical: false,
            circular: true,
            visible: 3,
            start: 0,
            scroll: 1,

            beforeStart: null,
            afterEnd: null
        }, o || {});

        return this.each(function() {                           // Returns the element collection. Chainable.
            var running = false, animCss = o.vertical ? "top" : "left", sizeCss = o.vertical ? "height" : "width";
            var div = $(this), ul = $("ul", div), tLi = $("li", ul), tl = tLi.size(), v = o.visible;

            if (tl <= 1) {
                if (o.btnPrev) { $(o.btnPrev).hide() }
                if (o.btnNext) { $(o.btnNext).hide() }
                if (o.curInd) { $(o.curInd).hide() }
                $('.carousel ul li').css("display", "block");
                $('#share1').css({ "left": "20px", "bottom": "23px" })
                if ($(this).children("ul").children("li").hasClass("sold")) {
                    $('#share1').hide();
                }
                return false;
            }

            if (o.circular) {
                ul.prepend(tLi.slice(tl - v - 1 + 1).clone())
              .append(tLi.slice(0, v).clone());
                o.start += v;
            }
            $('.carousel ul li').css("display", "block");

            var li = $("li", ul), itemLength = li.size(), curr = o.start;
            div.css("visibility", "visible");
            if ($(vis()).hasClass("sold")) {
                $("#share1, #share2, #share3").hide();
            }
            li.css({ overflow: "hidden", float: o.vertical ? "none" : "left" });
            ul.css({ margin: "0", padding: "0", position: "relative", "list-style-type": "none", "z-index": "1" });
            div.css({ overflow: "hidden", position: "relative", "z-index": "2", left: "0px" });

            var liSize = o.vertical ? height(li) : width(li);   // Full li size(incl margin)-Used for animation
            var ulSize = liSize * itemLength;                   // size of full ul(total length, not just for the visible items)
            var divSize = liSize * v;                           // size of entire div(total length for just the visible items)
            var int = null;

            li.css({ width: li.width(), height: li.height() });
            ul.css(sizeCss, ulSize + "px").css(animCss, -(curr * liSize));

            div.css(sizeCss, divSize + "px");                     // Width of the DIV. length of visible images

            if (o.btnPrev)
                $(o.btnPrev).click(function() {
                    //							 	int = window.clearInterval(int)
                    $.fn.jCarouselLite.stop();
                    return go(curr - o.scroll);
                });

            if (o.btnNext)
                $(o.btnNext).click(function() {
                    //							int = window.clearInterval(int)
                    $.fn.jCarouselLite.stop();
                    return go(curr + o.scroll);
                });

            if (o.curInd)
                $(o.curInd).append(li.slice(curr).attr("rel"));

            if (o.btnGo)
                $.each(o.btnGo, function(i, val) {
                    $(val).click(function() {
                        return go(o.circular ? o.visible + i : i);
                    });
                });

            if (o.mouseWheel && div.mousewheel)
                div.mousewheel(function(e, d) {
                    return d > 0 ? go(curr - o.scroll) : go(curr + o.scroll);
                });

            if (o.auto)
                window.int = setInterval(function() {
                    go(curr + o.scroll);
                }, o.auto + o.speed);
            function vis() {
                return li.slice(curr).slice(0, v);
            };

            function go(to) {
                if (!running) {

                    if (o.beforeStart)
                        o.beforeStart.call(this, vis());



                    if (o.circular) {            // If circular we are in first or last, then goto the other end
                        if (to <= o.start - v - 1) {           // If first, then goto last
                            ul.css(animCss, -((itemLength - (v * 2)) * liSize) + "px");
                            // If "scroll" > 1, then the "to" might not be equal to the condition; it can be lesser depending on the number of elements.
                            curr = to == o.start - v - 1 ? itemLength - (v * 2) - 1 : itemLength - (v * 2) - o.scroll;
                        } else if (to >= itemLength - v + 1) { // If last, then goto first
                            ul.css(animCss, -((v) * liSize) + "px");
                            // If "scroll" > 1, then the "to" might not be equal to the condition; it can be greater depending on the number of elements.
                            curr = to == itemLength - v + 1 ? v + 1 : v + o.scroll;
                        } else curr = to;
                    } else {                    // If non-circular and to points to first or last, we just return.
                        if (to < 0 || to > itemLength - v) return;
                        else curr = to;
                    }                           // If neither overrides it, the curr will still be "to" and we can proceed.
                    if (o.curInd)
                        $(o.curInd).html(li.slice(curr).attr("title"));

                    running = true;
                    ul.animate(
                    animCss == "left" ? { left: -(curr * liSize)} : { top: -(curr * liSize) }, o.speed, o.easing,
                    function() {
                        if (o.afterEnd)
                            o.afterEnd.call(this, vis());
                        running = false;
                    }
                );
                    // Disable buttons when the carousel reaches the last/first, and enable when not
                    if (!o.circular) {
                        $(o.btnPrev + "," + o.btnNext).removeClass("disabled");
                        $((curr - o.scroll < 0 && o.btnPrev)
                        ||
                       (curr + o.scroll > itemLength - v && o.btnNext)
                        ||
                       []
                     ).addClass("disabled");
                    }

                }
                return false;
            };
        });
    };

    function css(el, prop) {
        return parseInt($.css(el[0], prop)) || 0;
    };
    function width(el) {
        return el[0].offsetWidth + css(el, 'marginLeft') + css(el, 'marginRight');
    };
    function height(el) {
        return el[0].offsetHeight + css(el, 'marginTop') + css(el, 'marginBottom');
    };
    $.fn.jCarouselLite.stop = function() {
        int = window.clearInterval(int);
    }

})(jQuery);

(function($) {
    $.facebox = function(data, klass) {
        $.facebox.loading()

        if (data.ajax) fillFaceboxFromAjax(data.ajax, klass)
        else if (data.div) fillFaceboxFromHref(data.div, klass)
        else if ($.isFunction(data)) data.call($)
        else $.facebox.reveal(data, klass)
    }

    /*
    * Public, $.facebox methods
    */

    $.extend($.facebox, {
        settings: {
            opacity: 0.5,
            overlay: true,
            useIframe: false,
            frameWidth: 476,
            frameHeight: 571,
            loadingImage: 'images/loading.gif',
            closeImage: 'images/img-close.gif',
            imageTypes: ['png', 'jpg', 'jpeg', 'gif'],
            faceboxHtml: '\
    <div id="facebox" style="display:none;"> \
      <div class="popup"> \
        <table> \
          <tbody> \
            <tr> \
              <td class="body"> \
                <div class="content"> \
                </div> \
              </td> \
            </tr> \
          </tbody> \
        </table> \
      </div> \
    </div>'
        },

        loading: function() {
            init()
            if ($('#facebox .loading').length == 1) return true
            showOverlay()

            $('#facebox .content').empty()
            $('#facebox .body').children().hide().end().
        append('<div class="loading"><img src="' + $.facebox.settings.loadingImage + '"/></div>')

            $('#facebox').css({
                top: getPageScroll()[1] + (getPageHeight() / 10),
                left: $(window).width() / 2 - 205
            }).show()

            $(document).bind('keydown.facebox', function(e) {
                if (e.keyCode == 27) $.facebox.close()
                return true
            })
            $(document).trigger('loading.facebox')
        },

        reveal: function(data, klass) {
            $(document).trigger('beforeReveal.facebox')
            if (klass) $('#facebox .content').addClass(klass)
            $('#facebox .content').append(data)
            $('#facebox .loading').remove()
            $('#facebox .body').children().fadeIn('normal')
            $('#facebox').css('left', $(window).width() / 2 - ($('#facebox table').width() / 2))
            $(document).trigger('reveal.facebox').trigger('afterReveal.facebox')
        },

        close: function() {
            $(document).trigger('close.facebox')
            return false
        }
    })

    /*
    * Public, $.fn methods
    */

    $.fn.facebox = function(settings) {
        init(settings)

        function clickHandler() {
            $.facebox.loading(true)

            // support for rel="facebox.inline_popup" syntax, to add a class
            // also supports deprecated "facebox[.inline_popup]" syntax
            var klass = this.rel.match(/facebox\[?\.(\w+)\]?/)
            if (klass) klass = klass[1]

            fillFaceboxFromHref(this.href, klass)
            return false
        }

        return this.bind('click.facebox', clickHandler)
    }

    /*
    * Private methods
    */

    // called one time to setup facebox on this page
    function init(settings) {
        if ($.facebox.settings.inited) return true
        else $.facebox.settings.inited = true

        $(document).trigger('init.facebox')
        makeCompatible()

        var imageTypes = $.facebox.settings.imageTypes.join('|')
        $.facebox.settings.imageTypesRegexp = new RegExp('\.(' + imageTypes + ')$', 'i')

        if (settings) $.extend($.facebox.settings, settings)
        $('body').append($.facebox.settings.faceboxHtml)

        var preload = [new Image(), new Image()]
        preload[0].src = $.facebox.settings.closeImage
        preload[1].src = $.facebox.settings.loadingImage

        $('#facebox').find('.b:first, .bl, .br, .tl, .tr').each(function() {
            preload.push(new Image())
            preload.slice(-1).src = $(this).css('background-image').replace(/url\((.+)\)/, '$1')
        })

        $('#facebox .close').click($.facebox.close)
        $('#facebox .close_image').attr('src', $.facebox.settings.closeImage)
    }

    // getPageScroll() by quirksmode.com
    function getPageScroll() {
        var xScroll, yScroll;
        if (self.pageYOffset) {
            yScroll = self.pageYOffset;
            xScroll = self.pageXOffset;
        } else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
            yScroll = document.documentElement.scrollTop;
            xScroll = document.documentElement.scrollLeft;
        } else if (document.body) {// all other Explorers
            yScroll = document.body.scrollTop;
            xScroll = document.body.scrollLeft;
        }
        return new Array(xScroll, yScroll)
    }

    // Adapted from getPageSize() by quirksmode.com
    function getPageHeight() {
        var windowHeight
        if (self.innerHeight) {	// all except Explorer
            windowHeight = self.innerHeight;
        } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
            windowHeight = document.documentElement.clientHeight;
        } else if (document.body) { // other Explorers
            windowHeight = document.body.clientHeight;
        }
        return windowHeight
    }

    // Backwards compatibility
    function makeCompatible() {
        var $s = $.facebox.settings

        $s.loadingImage = $s.loading_image || $s.loadingImage
        $s.closeImage = $s.close_image || $s.closeImage
        $s.imageTypes = $s.image_types || $s.imageTypes
        $s.faceboxHtml = $s.facebox_html || $s.faceboxHtml
    }

    // Figures out what you want to display and displays it
    // formats are:
    //     div: #id
    //   image: blah.extension
    //    ajax: anything else
    function fillFaceboxFromHref(href, klass) {
        // div
        if (href.match(/#/)) {
            var url = window.location.href.split('#')[0]
            var target = href.replace(url, '')
            $.facebox.reveal($(target).show().replaceWith("<div id='facebox_moved'></div>"), klass)

            // image
        } else if (href.match($.facebox.settings.imageTypesRegexp)) {
            fillFaceboxFromImage(href, klass)
            // ajax
        } else {
            fillFaceboxFromAjax(href, klass)
        }
    }

    function fillFaceboxFromAjax(href, klass) {
        if ($.facebox.settings.useIframe == true) {
            $.facebox.reveal('<iframe id="framed' + Math.round(Math.random() * 1000) + '" name="framed' + Math.round(Math.random() * 1000) + '" frameborder="0" hspace="0" scrolling="no" src="' + href + '" width="' + $.facebox.settings.frameWidth + '" height="' + $.facebox.settings.frameHeight + '"></iframe>', klass);

        } else {
            $.get(href, function(data) { $.facebox.reveal(data, klass); })

        }
    }

    function skipOverlay() {
        return $.facebox.settings.overlay == false || $.facebox.settings.opacity === null
    }

    function showOverlay() {
        if (skipOverlay()) return

        if ($('#facebox_overlay').length == 0)
            $("body").append('<div id="facebox_overlay" class="facebox_hide"></div>')

        $('#facebox_overlay').hide().addClass("facebox_overlayBG")
      .css('opacity', $.facebox.settings.opacity)
      .show()
        return false
        //was after css statement above  .click(function() { $(document).trigger('close.facebox') })
    }

    function hideOverlay() {
        if (skipOverlay()) return

        $('#facebox_overlay').hide(0, function() {
            $("#facebox_overlay").removeClass("facebox_overlayBG")
            $("#facebox_overlay").addClass("facebox_hide")
            $("#facebox_overlay").remove()
        })

        return false
    }

    /*
    * Bindings
    */

    $(document).bind('close.facebox', function() {
        $(document).unbind('keydown.facebox')
        $('#facebox').fadeOut(function() {
            if ($('#facebox_moved').length == 0) $('#facebox .content').removeClass().addClass('content')
            else $('#facebox_moved').replaceWith($('#facebox .content').children().hide())
            hideOverlay()
            $('#facebox .loading').remove()
        })
    })

})(jQuery);

jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

/**
* Autotab - jQuery plugin 1.1b
* http://www.lousyllama.com/sandbox/jquery-autotab
* 
* Copyright (c) 2008 Matthew Miller
* 
* Dual licensed under the MIT and GPL licenses:
*   http://www.opensource.org/licenses/mit-license.php
*   http://www.gnu.org/licenses/gpl.html
* 
* Revised: 2008-09-10 16:55:08
*/

(function($) {
    // Look for an element based on ID or name
    var check_element = function(name) {
        var obj = null;
        var check_id = $('#' + name);
        var check_name = $('input[name=' + name + ']');

        if (check_id != undefined)
            obj = check_id;
        else if (check_name != undefined)
            obj = check_name;

        return obj;
    };

    /**
    * autotab_magic automatically establishes autotabbing with the
    * next and previous elements as provided by :input.
    * 
    * autotab_magic should called after applying filters, if used.
    * If any filters are applied after calling autotab_magic, then
    * Autotab may not protect against brute force typing.
    * 
    * @name	autotab_magic
    * @param	focus	Applies focus on the specified element
    * @example	$(':input').autotab_magic();
    */
    $.fn.autotab_magic = function(focus) {
        for (var i = 0; i < this.length; i++) {
            var n = i + 1;
            var p = i - 1;

            if (i > 0 && n < this.length)
                $(this[i]).autotab({ target: $(this[n]), previous: $(this[p]) });
            else if (i > 0)
                $(this[i]).autotab({ previous: $(this[p]) });
            else
                $(this[i]).autotab({ target: $(this[n]) });

            // Set the focus on the specified element
            if (focus != null && (isNaN(focus) && focus == $(this[i]).attr('id')) || (!isNaN(focus) && focus == i))
                $(this[i]).focus();
        }
    };

    /**
    * This will take any of the text that is typed and
    * format it according to the options specified.
    * 
    * Option values:
    *	format		text|number|alphanumeric|all|custom
    *	- Text			Allows all characters except numbers
    *	- Number		Allows only numbers
    *	- Alphanumeric	Allows only letters and numbers
    *	- All			Allows any and all characters
    *	- Custom		Allows developer to provide their own filter
    *
    *	uppercase	true|false
    *	- Converts a string to UPPERCASE
    * 
    *	lowercase	true|false
    *	- Converts a string to lowecase
    * 
    *	nospace		true|false
    *	- Remove spaces in the user input
    * 
    *	pattern		null|(regular expression)
    *	- Custom regular expression for the filter
    * 
    * @name	autotab_filter
    * @param	options		Can be a string, function or a list of options. If a string or
    *						function is passed, it will be assumed to be a format option.
    * @example	$('#number1, #number2, #number3').autotab_filter('number');
    * @example	$('#product_key').autotab_filter({ format: 'alphanumeric', nospace: true });
    * @example	$('#unique_id').autotab_filter({ format: 'custom', pattern: '[^0-9\.]' });
    */
    $.fn.autotab_filter = function(options) {
        var defaults = {
            format: 'all',
            uppercase: false,
            lowercase: false,
            nospace: false,
            pattern: null
        };

        if (typeof options == 'string' || typeof options == 'function')
            defaults.format = options;
        else
            $.extend(defaults, options);

        for (var i = 0; i < this.length; i++) {
            $(this[i]).bind('keyup', function(e) {
                var val = this.value;

                switch (defaults.format) {
                    case 'text':
                        var pattern = new RegExp('[0-9]+', 'g');
                        val = val.replace(pattern, '');
                        break;

                    case 'alpha':
                        var pattern = new RegExp('[^a-zA-Z]+', 'g');
                        val = val.replace(pattern, '');
                        break;

                    case 'number':
                    case 'numeric':
                        var pattern = new RegExp('[^0-9]+', 'g');
                        val = val.replace(pattern, '');
                        break;

                    case 'alphanumeric':
                        var pattern = new RegExp('[^0-9a-zA-Z]+', 'g');
                        val = val.replace(pattern, '');
                        break;

                    case 'custom':
                        var pattern = new RegExp(defaults.pattern, 'g');
                        var val = val.replace(pattern, '');
                        break;

                    case 'all':
                    default:
                        if (typeof defaults.format == 'function')
                            var val = defaults.format(val);

                        break;
                }

                if (defaults.nospace) {
                    var pattern = new RegExp('[ ]+', 'g');
                    val = val.replace(pattern, '');
                }

                if (defaults.uppercase)
                    val = val.toUpperCase();

                if (defaults.lowercase)
                    val = val.toLowerCase();

                if (val != this.value)
                    this.value = val;
            });
        }
    };

    /**
    * Provides the autotabbing mechanism for the supplied element and passes
    * any formatting options to autotab_filter.
    * 
    * Refer to autotab_filter's description for a detailed explanation of
    * the options available.
    * 
    * @name	autotab
    * @param	options
    * @example	$('#phone').autotab({ format: 'number' });
    * @example	$('#username').autotab({ format: 'alphanumeric', target: 'password' });
    * @example	$('#password').autotab({ previous: 'username', target: 'confirm' });
    */
    $.fn.autotab = function(options) {
        var defaults = {
            format: 'all',
            maxlength: 2147483647,
            uppercase: false,
            lowercase: false,
            nospace: false,
            target: null,
            previous: null,
            pattern: null
        };

        $.extend(defaults, options);

        // Sets targets to element based on the name or ID
        // passed if they are not currently objects
        if (typeof defaults.target == 'string')
            defaults.target = check_element(defaults.target);

        if (typeof defaults.previous == 'string')
            defaults.previous = check_element(defaults.previous);

        var maxlength = $(this).attr('maxlength');

        // defaults.maxlength has not changed and maxlength was specified
        if (defaults.maxlength == 2147483647 && maxlength != 2147483647)
            defaults.maxlength = maxlength;
        // defaults.maxlength overrides maxlength
        else if (defaults.maxlength > 0)
            $(this).attr('maxlength', defaults.maxlength)
        // defaults.maxlength and maxlength have not been specified
        // A target cannot be used since there is no defined maxlength
        else
            defaults.target = null;

        if (defaults.format != 'all')
            $(this).autotab_filter(defaults);

        // Go to the previous element when backspace
        // is pressed in an empty input field
        return $(this).bind('keydown', function(e) {
            if (e.which == 8 && this.value.length == 0 && defaults.previous)
                defaults.previous.focus().val(defaults.previous.val());
        }).bind('keyup', function(e) {
            /**
            * Do not auto tab when the following keys are pressed
            * 8:	Backspace
            * 9:	Tab
            * 16:	Shift
            * 17:	Ctrl
            * 18:	Alt
            * 19:	Pause Break
            * 20:	Caps Lock
            * 27:	Esc
            * 33:	Page Up
            * 34:	Page Down
            * 35:	End
            * 36:	Home
            * 37:	Left Arrow
            * 38:	Up Arrow
            * 39:	Right Arrow
            * 40:	Down Arrow
            * 45:	Insert
            * 46:	Delete
            * 144:	Num Lock
            * 145:	Scroll Lock
            */
            var keys = [8, 9, 16, 17, 18, 19, 20, 27, 33, 34, 35, 36, 37, 38, 39, 40, 45, 46, 144, 145];

            if (e.which != 8) {
                var val = $(this).val();

                if ($.inArray(e.which, keys) == -1 && val.length == defaults.maxlength && defaults.target)
                    defaults.target.focus();
            }
        });
    };

})(jQuery);