jQuery(function () {
    jQuery('.form-block:not(.default) select').customSelect();
    jQuery('.sorting:not(.default) select').customSelect();
    $('a[rel=External]').attr('target', '_blank');
    initPressed();
    initCustomFile();
    clearFormFields({
        clearInputs: true,
        clearTextareas: true,
        passwordFieldText: true,
        addClassFocus: "focus",
        filterClass: "default"
    });
    initDrop();
    jQuery("#mainnav").lavaLamp({
        fx: "easeOutBack",
        speed: 500,
        homeLeft: 0,
        homeTop: 35
    });
    $('.slideshow').gallery({
        duration: 800,
        listOfSlides: '.content>ul>li',
        autoRotation: 10000,
        switcher: '.switcher>ul>li'
    });
    $('div.mini-porfolio').scrollGallery({
        duration: 500,
        btnPrev: 'a.btn-prev',
        btnNext: 'a.btn-next'
    });
    $('div.carousel').scrollGallery({
        duration: 1000,
        btnPrev: 'a.btn-prev',
        btnNext: 'a.btn-next'
    });
    initAccordion();
    $('div.mini-slideshow').scrollGallery({
        sliderHolder: 'div.holder',
        slider: '> ul',
        slides: '> li',
        autoRotation: true,
        switchTime: 7000,
        generatePagination: 'div.switcher',
        duration: 500
    });
    $('.gallery-box').scrollGallery({
        sliderHolder: 'div.holder',
        slider: '> ul',
        slides: '> li',
        autoRotation: true,
        switchTime: 7000,
        generatePagination: 'div.switcher',
        duration: 500
       });
});
// accordion function
function initAccordion() {
    var _activeClass = 'active';
    var _slideSpeed = 500;

    $('.accordion,.mini-accordion').each(function () {
        var _accordion = $(this);
        var _items = _accordion.find('li:has(div)');
        _items.each(function () {
            var _holder = $(this);
            var _opener = _holder.find('>.opener');
            var _slider = _holder.find('>div.slide');

            _opener.click(function () {
                var _levelItems = _holder.parent().children(':has(div)').not(_holder);

                if (_holder.hasClass(_activeClass)) {
                    _slider.slideUp(_slideSpeed, function () {
                        _holder.removeClass(_activeClass);
                    });
                } else {
                    _holder.addClass(_activeClass);
                    _slider.slideDown(_slideSpeed);

                    // collapse others
                    _levelItems.find('>div.slide:visible').slideUp(_slideSpeed, function () {
                        _levelItems.removeClass(_activeClass);
                    })
                }
                return false;
            });

            if (_holder.hasClass(_activeClass)) _slider.show();
            else _slider.hide();
        });
    });
}
//gallery plugin
(function ($) {
    $.fn.gallery = function (options) { return new Gallery(this.get(0), options); };

    function Gallery(context, options) { this.init(context, options); };

    Gallery.prototype = {
        options: {},
        init: function (context, options) {
            this.options = $.extend({
                duration: 700,
                listOfSlides: 'ul > li',
                nextBtn: 'a.link-next, a.btn-next, a.next',
                prevBtn: 'a.link-prev, a.btn-prev, a.prev',
                switcher: false,
                event: 'click'
            }, options || {});
            this.context = $(context);
            this.els = this.context.find(this.options.listOfSlides);
            this.width = this.els.outerWidth();
            this.nextBtn = this.context.find(this.options.nextBtn);
            this.prevBtn = this.context.find(this.options.prevBtn);
            this.count = this.els.index(this.els.filter(':last'));

            if (this.options.switcher) this.switcher = this.context.find(this.options.switcher);

            this.active = 0;
            if (this.active == 0) this.prev = this.count;
            else this.prev = this.active - 1;

            this.initEvent(this, this.nextBtn, this.prevBtn, true);
            this.initEvent(this, this.prevBtn, this.nextBtn, false);

            this.els.css({ marginLeft: -this.width }).eq(this.active).addClass('active').css({ marginLeft: 0 });

            if (this.options.switcher) this.initEventSwitcher(this, this.switcher);
            $(window).resize($.proxy(function () {
                this.width = this.els.outerWidth();
                this.els.css({ marginLeft: -this.width }).eq(this.active).addClass('active').css({ marginLeft: 0 });
            }, this));
        },
        calcPrev: function () {
            if (this.active == 0) this.prev = this.count;
            else this.prev = this.active - 1;
        },
        scrollElement: function ($this, side, speed) {
            if (side) {
                this.els.eq(this.active).css({
                    marginLeft: this.width
                }).animate({
                    marginLeft: 0
                }, {
                    queue: false,
                    duration: speed ? 0 : $this.options.duration,
                    complete: function () {
                        $this.els.removeClass('active').eq($this.active).addClass('active');
                    }
                });
                this.els.eq(this.prev).animate({
                    marginLeft: -this.width
                }, {
                    queue: false,
                    duration: speed ? 0 : $this.options.duration
                });
            } else {
                this.els.eq(this.active).css({
                    marginLeft: -this.width
                }).animate({
                    marginLeft: 0
                }, {
                    queue: false,
                    duration: speed ? 0 : $this.options.duration,
                    complete: function () {
                        $this.els.removeClass('active').eq($this.active).addClass('active');
                    }
                });
                this.els.eq(this.prev).animate({
                    marginLeft: this.width
                }, {
                    queue: false,
                    duration: speed ? 0 : $this.options.duration
                });
            }
            if (this.options.switcher) this.switcher.removeClass('active').eq(this.active).addClass('active');
        },
        initEvent: function ($this, addEventEl, addDisClass, dir) {
            addEventEl.bind($this.options.event, function () {
                $this.toPrepare(dir);
                return false;
            });
        },
        initEventSwitcher: function ($this, el) {
            el.bind($this.options.event, function () {
                $this.prev = $this.active;
                $this.active = $this.switcher.index($(this));

                if ($this.active > $this.prev) {
                    $this.scrollElement($this, true);
                }
                if ($this.active < $this.prev) {
                    $this.scrollElement($this, false);
                }
                return false;
            });
        },
        toPrepare: function (side) {
            if (side) {
                if (this.active == this.count) this.active = 0;
                else this.active++;

                if (this.active == 0) this.prev = this.count;
                else this.prev = this.active - 1;
            }
            else {
                if (this.active == 0) this.active = this.count;
                else this.active--;

                if (this.active == this.count) this.prev = 0;
                else this.prev = this.active + 1;
            }
            this.scrollElement(this, side);
        }
    }
} (jQuery));
//init drop
function initDrop() {
    $('#mainnav>li:has(".drop")').each(function () {
        var li = $(this);
        var drop = li.find('.drop');
        drop.find('li').addClass('noLava');
        var t;
        li.mouseenter(function () {
            drop.show().css({
                opacity: 0
            }).stop().animate({
                opacity: 1
            }, {
                queue: false,
                duration: 500
            });
        }).mouseleave(function () {
            drop.stop().animate({
                opacity: 0
            }, {
                queue: false,
                duration: 500,
                complete: function () {
                    drop.hide()
                }
            });
        });
    });
}
// pressed states
function initPressed() {
    var list = document.getElementsByTagName("*");
    for (var i = 0; i < list.length; i++) {
        if (list[i].className.indexOf("button") != -1) {
            list[i].onmousedown = function () {
                if (this.className.indexOf("pressed") == -1) this.className += " pressed";
            }
            list[i].onmouseup = function () {
                this.className = this.className.replace("pressed", "");
            }
            list[i].onmouseout = function () {
                this.className = this.className.replace("pressed", "");
            }
        }
    }
}
// custom upload input
function initCustomFile() {
    var inputs = document.getElementsByTagName('input');
    for (var i = 0; i < inputs.length; i++) {
        if (inputs[i].className.indexOf('file-input-area') != -1) {
            new customFileUpload(inputs[i]);
        }
    }
}
// custom file input module
function customFileUpload(obj, opt) {
    if (obj) {
        this.options = {
            jsActiveClass: 'file-input-js-active',
            fakeClass: 'text',
            hoverClass: 'hover'
        }
        this.fileInput = obj;
        this.fileInput.custClass = this;
        this.init();
    }
}
customFileUpload.prototype = {
    init: function () {
        this.getElements();
        this.setStyles();
        this.addEvents();
    },
    getElements: function () {
        this.fileInputParent = this.fileInput.parentNode;
        this.fileInputParent.className += ' ' + this.options.jsActiveClass;
        var tmpInputs = this.fileInput.parentNode.getElementsByTagName('input');
        for (var i = 0; i < tmpInputs.length; i++) {
            if (tmpInputs[i].className.indexOf(this.options.fakeClass) != -1) {
                this.fakeInput = tmpInputs[i];
                this.fakeInput.readOnly = true;
                break;
            }
        }
    },
    getFileName: function () {
        return this.fileInput.value.replace(/^[\s\S]*(?:\\|\/)([\s\S^\\\/]*)$/g, "$1");
    },
    setStyles: function () {
        // IE styling fix
        if ((/(MSIE)/gi).test(navigator.userAgent)) {
            this.tmpNode = document.createElement('span');
            this.fileInputParent.insertBefore(this.tmpNode, this.fileInput);
            this.fileInputParent.insertBefore(this.fileInput, this.tmpNode);
            this.fileInputParent.removeChild(this.tmpNode);
        }
        this.fileInput.style.opacity = 0;
        this.fileInput.style.filter = 'alpha(opacity=0)';
    },
    addEvents: function () {
        this.fileInput.onchange = this.bind(this.updateTitle, this);
        this.fileInput.onmouseover = this.bind(function () {
            this.fileInputParent.className += ' ' + this.options.hoverClass;
        }, this);
        this.fileInput.onmouseout = this.bind(function () {
            this.fileInputParent.className = this.fileInputParent.className.replace(' ' + this.options.hoverClass, '');
        }, this);
    },
    updateTitle: function () {
        if (this.fakeInput) {
            this.fakeInput.value = this.getFileName();
        }
    },
    bind: function (func, scope) {
        return function () {
            return func.apply(scope, arguments);
        }
    }
}
// clear fields
function clearFormFields(o) {
    if (o.clearInputs == null) o.clearInputs = true;
    if (o.clearTextareas == null) o.clearTextareas = true;
    if (o.passwordFieldText == null) o.passwordFieldText = false;
    if (o.addClassFocus == null) o.addClassFocus = false;
    if (!o.filter) o.filter = "default";
    if (o.clearInputs) {
        var inputs = document.getElementsByTagName("input");
        for (var i = 0; i < inputs.length; i++) {
            if ((inputs[i].type == "text" || inputs[i].type == "password") && inputs[i].className.indexOf(o.filterClass)) {
                inputs[i].valueHtml = inputs[i].value;
                inputs[i].onfocus = function () {
                    if (this.valueHtml == this.value) this.value = "";
                    if (this.fake) {
                        inputsSwap(this, this.previousSibling);
                        this.previousSibling.focus();
                    }
                    if (o.addClassFocus && !this.fake) {
                        this.className += " " + o.addClassFocus;
                        this.parentNode.className += " parent-" + o.addClassFocus;
                    }
                }
                inputs[i].onblur = function () {
                    if (this.value == "") {
                        this.value = this.valueHtml;
                        if (o.passwordFieldText && this.type == "password") inputsSwap(this, this.nextSibling);
                    }
                    if (o.addClassFocus) {
                        this.className = this.className.replace(o.addClassFocus, "");
                        this.parentNode.className = this.parentNode.className.replace("parent-" + o.addClassFocus, "");
                    }
                }
                if (o.passwordFieldText && inputs[i].type == "password") {
                    var fakeInput = document.createElement("input");
                    fakeInput.type = "text";
                    fakeInput.value = inputs[i].value;
                    fakeInput.className = inputs[i].className;
                    fakeInput.fake = true;
                    inputs[i].parentNode.insertBefore(fakeInput, inputs[i].nextSibling);
                    inputsSwap(inputs[i], null);
                }
            }
        }
    }
    if (o.clearTextareas) {
        var textareas = document.getElementsByTagName("textarea");
        for (var i = 0; i < textareas.length; i++) {
            if (textareas[i].className.indexOf(o.filterClass)) {
                textareas[i].valueHtml = textareas[i].value;
                textareas[i].onfocus = function () {
                    if (this.value == this.valueHtml) this.value = "";
                    if (o.addClassFocus) {
                        this.className += " " + o.addClassFocus;
                        this.parentNode.className += " parent-" + o.addClassFocus;
                    }
                }
                textareas[i].onblur = function () {
                    if (this.value == "") this.value = this.valueHtml;
                    if (o.addClassFocus) {
                        this.className = this.className.replace(o.addClassFocus, "");
                        this.parentNode.className = this.parentNode.className.replace("parent-" + o.addClassFocus, "");
                    }
                }
            }
        }
    }
    function inputsSwap(el, el2) {
        if (el) el.style.display = "none";
        if (el2) el2.style.display = "inline";
    }
}
// custom forms plugin
; (function ($) {
    // custom checkboxes module
    $.fn.customCheckbox = function (_options) {
        var _options = $.extend({
            checkboxStructure: '<div></div>',
            checkboxDisabled: 'disabled',
            checkboxDefault: 'checkboxArea',
            checkboxChecked: 'checkboxAreaChecked'
        }, _options);
        return this.each(function () {
            var checkbox = $(this);
            if (!checkbox.hasClass('outtaHere') && checkbox.is(':checkbox')) {
                var replaced = $(_options.checkboxStructure);
                this._replaced = replaced;
                if (checkbox.is(':disabled')) replaced.addClass(_options.checkboxDisabled);
                else if (checkbox.is(':checked')) replaced.addClass(_options.checkboxChecked);
                else replaced.addClass(_options.checkboxDefault);

                replaced.click(function () {
                    if (checkbox.is(':checked')) checkbox.removeAttr('checked');
                    else checkbox.attr('checked', 'checked');
                    changeCheckbox(checkbox);
                });
                checkbox.click(function () {
                    changeCheckbox(checkbox);
                });
                replaced.insertBefore(checkbox);
                checkbox.addClass('outtaHere');
            }
        });
        function changeCheckbox(_this) {
            _this.change();
            if (_this.is(':checked')) _this.get(0)._replaced.removeClass().addClass(_options.checkboxChecked);
            else _this.get(0)._replaced.removeClass().addClass(_options.checkboxDefault);
        }
    }
    // custom radios module
    $.fn.customRadio = function (_options) {
        var _options = $.extend({
            radioStructure: '<div></div>',
            radioDisabled: 'disabled',
            radioDefault: 'radioArea',
            radioChecked: 'radioAreaChecked'
        }, _options);
        return this.each(function () {
            var radio = $(this);
            if (!radio.hasClass('outtaHere') && radio.is(':radio')) {
                var replaced = $(_options.radioStructure);
                this._replaced = replaced;
                if (radio.is(':disabled')) replaced.addClass(_options.radioDisabled);
                else if (radio.is(':checked')) replaced.addClass(_options.radioChecked);
                else replaced.addClass(_options.radioDefault);
                replaced.click(function () {
                    if ($(this).hasClass(_options.radioDefault)) {
                        radio.attr('checked', 'checked');
                        changeRadio(radio.get(0));
                    }
                });
                radio.click(function () {
                    changeRadio(this);
                });
                replaced.insertBefore(radio);
                radio.addClass('outtaHere');
            }
        });
        function changeRadio(_this) {
            $(_this).change();
            $('input:radio[name=' + $(_this).attr("name") + ']').not(_this).each(function () {
                if (this._replaced && !$(this).is(':disabled')) this._replaced.removeClass().addClass(_options.radioDefault);
            });
            _this._replaced.removeClass().addClass(_options.radioChecked);
        }
    }
    // custom selects module
    $.fn.customSelect = function (_options) {
        var _options = $.extend({
            selectStructure: '<div class="selectArea"><span class="left"></span><span class="center"></span><a href="#" class="selectButton"></a><div class="disabled"></div></div>',
            hideOnMouseOut: false,
            copyClass: true,
            selectText: '.center',
            selectBtn: '.selectButton',
            selectDisabled: '.disabled',
            optStructure: '<div class="optionsDivVisible"><div class="select-top"></div><div class="select-center"><ul></ul><div class="select-bottom"></div></div>',
            optList: 'ul'
        }, _options);
        return this.each(function () {
            var select = $(this);
            if (!select.hasClass('outtaHere')) {
                if (select.is(':visible')) {
                    var hideOnMouseOut = _options.hideOnMouseOut;
                    var copyClass = _options.copyClass;
                    var replaced = $(_options.selectStructure);
                    var selectText = replaced.find(_options.selectText);
                    var selectBtn = replaced.find(_options.selectBtn);
                    var selectDisabled = replaced.find(_options.selectDisabled).hide();
                    var optHolder = $(_options.optStructure);
                    var optList = optHolder.find(_options.optList);
                    if (copyClass) optHolder.addClass('drop-' + select.attr('class')); replaced.addClass(select.attr('class'));

                    if (select.attr('disabled')) selectDisabled.show();
                    select.find('option').each(function () {
                        var selOpt = $(this);
                        var _opt = $('<li><a href="#">' + selOpt.html() + '</a></li>');
                        if (selOpt.attr('selected')) {
                            selectText.html(selOpt.html());
                            _opt.addClass('selected');
                        }
                        _opt.children('a').click(function () {
                            optList.find('li').removeClass('selected');
                            select.find('option').removeAttr('selected');
                            $(this).parent().addClass('selected');
                            selOpt.attr('selected', 'selected');
                            selectText.html(selOpt.html());
                            select.change();
                            optHolder.hide();
                            if (typeof Cufon === 'function') Cufon.refresh('.header-holder .select-form .center');
                            return false;
                        });
                        optList.append(_opt);
                    });
                    replaced.width(select.outerWidth());
                    replaced.insertBefore(select);
                    optHolder.css({
                        width: select.outerWidth(),
                        display: 'none',
                        position: 'absolute'
                    });
                    $(document.body).append(optHolder);

                    var optTimer;
                    replaced.hover(function () {
                        if (optTimer) clearTimeout(optTimer);
                    }, function () {
                        if (hideOnMouseOut) {
                            optTimer = setTimeout(function () {
                                optHolder.hide();
                            }, 200);
                        }
                    });
                    optHolder.hover(function () {
                        if (optTimer) clearTimeout(optTimer);
                    }, function () {
                        if (hideOnMouseOut) {
                            optTimer = setTimeout(function () {
                                optHolder.hide();
                            }, 200);
                        }
                    });
                    selectBtn.click(function () {
                        if (optHolder.is(':visible')) {
                            optHolder.hide();
                        }
                        else {
                            if (_activeDrop) _activeDrop.hide();
                            optHolder.children('ul').css({ height: 'auto', overflow: 'hidden' });
                            optHolder.css({
                                top: replaced.offset().top + replaced.outerHeight(),
                                left: replaced.offset().left,
                                display: 'block'
                            });
                            if (optHolder.children('ul').height() > 200) optHolder.children('ul').css({ height: 200, overflow: 'auto' });
                            _activeDrop = optHolder;
                        }
                        return false;
                    });
                    select.addClass('outtaHere');
                }
            }
        });
    }
    // event handler on DOM ready
    var _activeDrop;
    $(function () {
        $('body').click(hideOptionsClick)
        $(window).resize(hideOptions)
    });
    function hideOptions() {
        if (_activeDrop && _activeDrop.length) {
            _activeDrop.hide();
            _activeDrop = null;
        }
    }
    function hideOptionsClick(e) {
        if (_activeDrop && _activeDrop.length) {
            var f = false;
            $(e.target).parents().each(function () {
                if (this == _activeDrop) f = true;
            });
            if (!f) {
                _activeDrop.hide();
                _activeDrop = null;
            }
        }
    }
})(jQuery);
/**
* jquery.LavaLamp v1.3.5 - light up your menus with fluid, jQuery powered animations.
* Requires jQuery v1.2.3 or better from http://jquery.com
* Tested on jQuery 1.4.4, 1.3.2 and 1.2.6
* http://nixbox.com/projects/jquery-lavalamp/
* Source code Copyright (c) 2008, 2009, 2010 Jolyon Terwilliger, jolyon@nixbox.com
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*/
(function (d) {
    jQuery.fn.lavaLamp = function (a) {
        function e(g) { g = parseInt(g); return isNaN(g) ? 0 : g } a = d.extend({ target: "li", container: "", fx: "swing", speed: 500, click: function () { return true }, startItem: "", includeMargins: false, autoReturn: true, returnDelay: 0, setOnClick: true, homeTop: 0, homeLeft: 0, homeWidth: 0, homeHeight: 0, returnHome: false, autoResize: false }, a || {}); if (a.container == "") a.container = a.target; a.autoResize && d(window).resize(function () { d(a.target + ".selectedLava").trigger("mouseenter") }); return this.each(function () {
            function g(c) {
                c ||
(c = b); if (!a.includeMargins) { i = e(c.css("marginLeft")); j = e(c.css("marginTop")) } c = { left: c.position().left + i, top: c.position().top + j, width: c.outerWidth() - l, height: c.outerHeight() - m }; f.stop().animate(c, a.speed, a.fx)
            } d(this).css("position") == "static" && d(this).css("position", "relative"); if (a.homeTop || a.homeLeft) { var n = d("<" + a.container + ' class="homeLava"></' + a.container + ">").css({ left: a.homeLeft, top: a.homeTop, width: a.homeWidth, height: a.homeHeight, position: "absolute", display: "block" }); d(this).prepend(n) } var s =
location.pathname + location.search + location.hash, b, f, k = d(a.target + "[class!=noLava]", this), h, l = 0, m = 0, p = 0, q = 0, i = 0, j = 0; b = d(a.target + ".selectedLava", this); if (a.startItem != "") b = k.eq(a.startItem); if ((a.homeTop || a.homeLeft) && b.length < 1) {b = n;} if (b.length < 1) { var o = 0, r; k.each(function () { var c = d("a:first", this).attr("href"); if (s.indexOf(c) > -1 && c.length > o) { r = d(this); o = c.length } }); if (o > 0) b = r } if (b.length < 1) b = k.eq(0); b = d(b.eq(0).addClass("selectedLava")); k.bind("mouseenter", function () { if (h) { clearTimeout(h); h = null } g(d(this)) }).click(function (c) {
    if (a.setOnClick) {
        b.removeClass("selectedLava");
        b = d(this).addClass("selectedLava")
    } return a.click.apply(this, [c, this])
}); f = d("<" + a.container + ' class="backLava"><div class="leftLava"></div><div class="bottomLava"></div><div class="cornerLava"></div></' + a.container + ">").css({ position: "absolute", display: "block", margin: 0, padding: 0 }).prependTo(this); if (a.includeMargins) { p = e(b.css("marginTop")) + e(b.css("marginBottom")); q = e(b.css("marginLeft")) + e(b.css("marginRight")) } l = e(f.css("borderLeftWidth")) + e(f.css("borderRightWidth")) + e(f.css("paddingLeft")) +
e(f.css("paddingRight")) - q; m = e(f.css("borderTopWidth")) + e(f.css("borderBottomWidth")) + e(f.css("paddingTop")) + e(f.css("paddingBottom")) - p; if ((a.homeTop || a.homeLeft) && b.length < 1) f.css({ left: a.homeLeft, top: a.homeTop, width: a.homeWidth, height: a.homeHeight }); else { if (!a.includeMargins) { i = e(b.css("marginLeft")); j = e(b.css("marginTop")) } f.css({ left: b.position().left + i, top: b.position().top + j, width: b.outerWidth() - l, height: b.outerHeight() - m }) } d(this).bind("mouseleave", function () {
    var c = null; if (a.returnHome) c = n; else if (!a.autoReturn) return true;
    if (a.returnDelay) { h && clearTimeout(h); h = setTimeout(function () { g(c) }, a.returnDelay) } else g(c); return true
})
        })
    } 
})(jQuery);
/*
* jQuery Easing v1.3 - http://gsgd.co.uk/sandbox/jquery/easing/
*
* Uses the built in easing capabilities added In jQuery 1.1
* to offer multiple easing options
*
* TERMS OF USE - jQuery Easing
* 
* Open source under the BSD License. 
* 
* Copyright © 2008 George McGinley Smith
* All rights reserved.
* 
* Redistribution and use in source and binary forms, with or without modification, 
* are permitted provided that the following conditions are met:
* 
* Redistributions of source code must retain the above copyright notice, this list of 
* conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list 
* of conditions and the following disclaimer in the documentation and/or other materials 
* provided with the distribution.
* 
* Neither the name of the author nor the names of contributors may be used to endorse 
* or promote products derived from this software without specific prior written permission.
* 
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
*  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
*  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
*  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
*  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
* OF THE POSSIBILITY OF SUCH DAMAGE. 
*
*/

// t: current time, b: begInnIng value, c: change In value, d: duration
jQuery.easing['jswing'] = jQuery.easing['swing'];

jQuery.extend(jQuery.easing,
{
    def: 'easeOutQuad',
    swing: function (x, t, b, c, d) {
        //alert(jQuery.easing.default);
        return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
    },
    easeInQuad: function (x, t, b, c, d) {
        return c * (t /= d) * t + b;
    },
    easeOutQuad: function (x, t, b, c, d) {
        return -c * (t /= d) * (t - 2) + b;
    },
    easeInOutQuad: function (x, t, b, c, d) {
        if ((t /= d / 2) < 1) return c / 2 * t * t + b;
        return -c / 2 * ((--t) * (t - 2) - 1) + b;
    },
    easeInCubic: function (x, t, b, c, d) {
        return c * (t /= d) * t * t + b;
    },
    easeOutCubic: function (x, t, b, c, d) {
        return c * ((t = t / d - 1) * t * t + 1) + b;
    },
    easeInOutCubic: function (x, t, b, c, d) {
        if ((t /= d / 2) < 1) return c / 2 * t * t * t + b;
        return c / 2 * ((t -= 2) * t * t + 2) + b;
    },
    easeInQuart: function (x, t, b, c, d) {
        return c * (t /= d) * t * t * t + b;
    },
    easeOutQuart: function (x, t, b, c, d) {
        return -c * ((t = t / d - 1) * t * t * t - 1) + b;
    },
    easeInOutQuart: function (x, t, b, c, d) {
        if ((t /= d / 2) < 1) return c / 2 * t * t * t * t + b;
        return -c / 2 * ((t -= 2) * t * t * t - 2) + b;
    },
    easeInQuint: function (x, t, b, c, d) {
        return c * (t /= d) * t * t * t * t + b;
    },
    easeOutQuint: function (x, t, b, c, d) {
        return c * ((t = t / d - 1) * t * t * t * t + 1) + b;
    },
    easeInOutQuint: function (x, t, b, c, d) {
        if ((t /= d / 2) < 1) return c / 2 * t * t * t * t * t + b;
        return c / 2 * ((t -= 2) * t * t * t * t + 2) + b;
    },
    easeInSine: function (x, t, b, c, d) {
        return -c * Math.cos(t / d * (Math.PI / 2)) + c + b;
    },
    easeOutSine: function (x, t, b, c, d) {
        return c * Math.sin(t / d * (Math.PI / 2)) + b;
    },
    easeInOutSine: function (x, t, b, c, d) {
        return -c / 2 * (Math.cos(Math.PI * t / d) - 1) + b;
    },
    easeInExpo: function (x, t, b, c, d) {
        return (t == 0) ? b : c * Math.pow(2, 10 * (t / d - 1)) + b;
    },
    easeOutExpo: function (x, t, b, c, d) {
        return (t == d) ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b;
    },
    easeInOutExpo: function (x, t, b, c, d) {
        if (t == 0) return b;
        if (t == d) return b + c;
        if ((t /= d / 2) < 1) return c / 2 * Math.pow(2, 10 * (t - 1)) + b;
        return c / 2 * (-Math.pow(2, -10 * --t) + 2) + b;
    },
    easeInCirc: function (x, t, b, c, d) {
        return -c * (Math.sqrt(1 - (t /= d) * t) - 1) + b;
    },
    easeOutCirc: function (x, t, b, c, d) {
        return c * Math.sqrt(1 - (t = t / d - 1) * t) + b;
    },
    easeInOutCirc: function (x, t, b, c, d) {
        if ((t /= d / 2) < 1) return -c / 2 * (Math.sqrt(1 - t * t) - 1) + b;
        return c / 2 * (Math.sqrt(1 - (t -= 2) * t) + 1) + b;
    },
    easeInElastic: function (x, t, b, c, d) {
        var s = 1.70158; var p = 0; var a = c;
        if (t == 0) return b; if ((t /= d) == 1) return b + c; if (!p) p = d * .3;
        if (a < Math.abs(c)) { a = c; var s = p / 4; }
        else var s = p / (2 * Math.PI) * Math.asin(c / a);
        return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
    },
    easeOutElastic: function (x, t, b, c, d) {
        var s = 1.70158; var p = 0; var a = c;
        if (t == 0) return b; if ((t /= d) == 1) return b + c; if (!p) p = d * .3;
        if (a < Math.abs(c)) { a = c; var s = p / 4; }
        else var s = p / (2 * Math.PI) * Math.asin(c / a);
        return a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) + c + b;
    },
    easeInOutElastic: function (x, t, b, c, d) {
        var s = 1.70158; var p = 0; var a = c;
        if (t == 0) return b; if ((t /= d / 2) == 2) return b + c; if (!p) p = d * (.3 * 1.5);
        if (a < Math.abs(c)) { a = c; var s = p / 4; }
        else var s = p / (2 * Math.PI) * Math.asin(c / a);
        if (t < 1) return -.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
        return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p) * .5 + c + b;
    },
    easeInBack: function (x, t, b, c, d, s) {
        if (s == undefined) s = 1.70158;
        return c * (t /= d) * t * ((s + 1) * t - s) + b;
    },
    easeOutBack: function (x, t, b, c, d, s) {
        if (s == undefined) s = 1.70158;
        return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
    },
    easeInOutBack: function (x, t, b, c, d, s) {
        if (s == undefined) s = 1.70158;
        if ((t /= d / 2) < 1) return c / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b;
        return c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b;
    },
    easeInBounce: function (x, t, b, c, d) {
        return c - jQuery.easing.easeOutBounce(x, d - t, 0, c, d) + b;
    },
    easeOutBounce: function (x, t, b, c, d) {
        if ((t /= d) < (1 / 2.75)) {
            return c * (7.5625 * t * t) + b;
        } else if (t < (2 / 2.75)) {
            return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b;
        } else if (t < (2.5 / 2.75)) {
            return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b;
        } else {
            return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b;
        }
    },
    easeInOutBounce: function (x, t, b, c, d) {
        if (t < d / 2) return jQuery.easing.easeInBounce(x, t * 2, 0, c, d) * .5 + b;
        return jQuery.easing.easeOutBounce(x, t * 2 - d, 0, c, d) * .5 + c * .5 + b;
    }
});

/*
*
* TERMS OF USE - EASING EQUATIONS
* 
* Open source under the BSD License. 
* 
* Copyright © 2001 Robert Penner
* All rights reserved.
* 
* Redistribution and use in source and binary forms, with or without modification, 
* are permitted provided that the following conditions are met:
* 
* Redistributions of source code must retain the above copyright notice, this list of 
* conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list 
* of conditions and the following disclaimer in the documentation and/or other materials 
* provided with the distribution.
* 
* Neither the name of the author nor the names of contributors may be used to endorse 
* or promote products derived from this software without specific prior written permission.
* 
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
*  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
*  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
*  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
*  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
* OF THE POSSIBILITY OF SUCH DAMAGE. 
*
*/

// scrolling gallery plugin
jQuery.fn.scrollGallery = function (_options) {
    var _options = jQuery.extend({
        sliderHolder: '>div',
        slider: '>ul',
        slides: '>li',
        pagerLinks: 'div.pager a',
        btnPrev: 'a.link-prev',
        btnNext: 'a.link-next',
        activeClass: 'active',
        disabledClass: 'disabled',
        generatePagination: 'div.pg-holder',
        curNum: 'em.scur-num',
        allNum: 'em.sall-num',
        circleSlide: true,
        pauseClass: 'gallery-paused',
        pauseButton: 'none',
        pauseOnHover: true,
        autoRotation: false,
        stopAfterClick: false,
        switchTime: 5000,
        duration: 650,
        easing: 'swing',
        event: 'click',
        afterInit: false,
        vertical: false,
        step: false,
        initStep: 0
    }, _options);


    return this.each(function () {
        // gallery options
        var _this = jQuery(this);
        var _sliderHolder = jQuery(_options.sliderHolder, _this);
        var _slider = jQuery(_options.slider, _sliderHolder);
        var _slides = jQuery(_options.slides, _slider);
        var _btnPrev = jQuery(_options.btnPrev, _this);
        var _btnNext = jQuery(_options.btnNext, _this);
        var _pagerLinks = jQuery(_options.pagerLinks, _this);
        var _generatePagination = jQuery(_options.generatePagination, _this);
        var _curNum = jQuery(_options.curNum, _this);
        var _allNum = jQuery(_options.allNum, _this);
        var _pauseButton = jQuery(_options.pauseButton, _this);
        var _pauseOnHover = _options.pauseOnHover;
        var _pauseClass = _options.pauseClass;
        var _autoRotation = _options.autoRotation;
        var _activeClass = _options.activeClass;
        var _disabledClass = _options.disabledClass;
        var _easing = _options.easing;
        var _duration = _options.duration;
        var _switchTime = _options.switchTime;
        var _controlEvent = _options.event;
        var _step = _options.step;
        var _vertical = _options.vertical;
        var _circleSlide = _options.circleSlide;
        var _stopAfterClick = _options.stopAfterClick;
        var _afterInit = _options.afterInit;

        // gallery init
        if (!_slides.length) return;
        var _currentStep = _options.initStep;
        var _sumWidth = 0;
        var _sumHeight = 0;
        var _hover = false;
        var _stepWidth;
        var _stepHeight;
        var _stepCount;
        var _offset;
        var _timer;

        _slides.each(function () {
            _sumWidth += $(this).outerWidth(true);
            _sumHeight += $(this).outerHeight(true);
        });

        // calculate gallery offset
        function recalcOffsets() {
            if (_vertical) {
                if (_step) {
                    _stepHeight = _slides.eq(_currentStep).outerHeight(true);
                    _stepCount = Math.ceil((_sumHeight - _sliderHolder.height()) / _stepHeight) + 1;
                    _offset = -_stepHeight * _currentStep;
                } else {
                    _stepHeight = _sliderHolder.height();
                    _stepCount = Math.ceil(_sumHeight / _stepHeight);
                    _offset = -_stepHeight * _currentStep;
                    if (_offset < _stepHeight - _sumHeight) _offset = _stepHeight - _sumHeight;
                }
            } else {
                if (_step) {
                    _stepWidth = _slides.eq(_currentStep).outerWidth(true) * _step;
                    _stepCount = Math.ceil((_sumWidth - _sliderHolder.width()) / _stepWidth) + 1;
                    _offset = -_stepWidth * _currentStep;
                    if (_offset < _sliderHolder.width() - _sumWidth) _offset = _sliderHolder.width() - _sumWidth;
                } else {
                    _stepWidth = _sliderHolder.width();
                    _stepCount = Math.ceil(_sumWidth / _stepWidth);
                    _offset = -_stepWidth * _currentStep;
                    if (_offset < _stepWidth - _sumWidth) _offset = _stepWidth - _sumWidth;
                }
            }
        }

        // gallery control
        if (_btnPrev.length) {
            _btnPrev.bind(_controlEvent, function () {
                if (_stopAfterClick) stopAutoSlide();
                prevSlide();
                return false;
            });
        }
        if (_btnNext.length) {
            _btnNext.bind(_controlEvent, function () {
                if (_stopAfterClick) stopAutoSlide();
                nextSlide();
                return false;
            });
        }
        if (_generatePagination.length) {
            _generatePagination.empty();
            recalcOffsets();
            _generatePagination.each(function () {
                var _list = $('<ul />');
                for (var i = 0; i < _stepCount; i++) $('<li><a href="#">' + (i + 1) + '</a></li>').appendTo(_list);
                _list.appendTo($(this));
            })
        }
        _generatePagination.each(function () {
            $(this).find('a').each(function (_ind) {
                jQuery(this).bind(_controlEvent, function () {
                    if (_currentStep != _ind) {
                        if (_stopAfterClick) stopAutoSlide();
                        _currentStep = _ind;
                        switchSlide();
                    }
                    return false;
                });
            });
        });

        // gallery animation
        function prevSlide() {
            recalcOffsets();
            if (_currentStep > 0) _currentStep--;
            else if (_circleSlide) _currentStep = _stepCount - 1;
            switchSlide();
        }
        function nextSlide() {
            recalcOffsets();
            if (_currentStep < _stepCount - 1) _currentStep++;
            else if (_circleSlide) _currentStep = 0;
            switchSlide();
        }
        function refreshStatus() {
            if (_generatePagination.length) {
                _generatePagination.each(function () {
                    $(this).find('a').removeClass(_activeClass).eq(_currentStep).addClass(_activeClass);
                });
            }
            if (!_circleSlide) {
                _btnPrev.removeClass(_disabledClass);
                _btnNext.removeClass(_disabledClass);
                if (_currentStep == 0) _btnPrev.addClass(_disabledClass);
                if (_currentStep == _stepCount - 1) _btnNext.addClass(_disabledClass);
            }
            if (_curNum.length) _curNum.text(_currentStep + 1);
            if (_allNum.length) _allNum.text(_stepCount);
        }
        function switchSlide() {
            recalcOffsets();
            if (_vertical) _slider.animate({ marginTop: _offset }, { duration: _duration, queue: false, easing: _easing });
            else _slider.animate({ marginLeft: _offset }, { duration: _duration, queue: false, easing: _easing });
            refreshStatus();
            autoSlide();
        }

        // autoslide function
        function stopAutoSlide() {
            if (_timer) clearTimeout(_timer);
            _autoRotation = false;
        }
        function autoSlide() {
            if (!_autoRotation || _hover) return;
            if (_timer) clearTimeout(_timer);
            _timer = setTimeout(nextSlide, _switchTime + _duration);
        }
        if (_pauseOnHover) {
            _this.hover(function () {
                _hover = true;
                if (_timer) clearTimeout(_timer);
            }, function () {
                _hover = false;
                autoSlide();
            });
        }
        recalcOffsets();
        _slider.css("marginLeft", _offset);
        refreshStatus();
        autoSlide();

        // pause buttton
        if (_pauseButton.length) {
            _pauseButton.click(function () {
                if (_this.hasClass(_pauseClass)) {
                    _this.removeClass(_pauseClass);
                    _autoRotation = true;
                    autoSlide();
                } else {
                    _this.addClass(_pauseClass);
                    stopAutoSlide();
                }
                return false;
            });
        }

        if (_afterInit && typeof _afterInit === 'function') _afterInit(_this, _slides);
    });
}
      // slideshow plugin
      jQuery.fn.fadeGallery = function (_options) {
          var _options = jQuery.extend({
              slideElements: 'div.slideset > div',
              pagerLinks: 'div.pager a',
              btnNext: 'a.next',
              btnPrev: 'a.prev',
              btnPlayPause: 'a.play-pause',
              btnPlay: 'a.play',
              btnPause: 'a.pause',
              pausedClass: 'paused',
              disabledClass: 'disabled',
              playClass: 'playing',
              activeClass: 'active',
              currentNum: false,
              allNum: false,
              startSlide: null,
              noCircle: false,
              pauseOnHover: true,
              autoRotation: false,
              autoHeight: false,
              onChange: false,
              switchTime: 3000,
              duration: 650,
              event: 'click',
              scrollGallery: null
          }, _options);

          return this.each(function () {
              // gallery options
              var _this = jQuery(this);
              var _slides = jQuery(_options.slideElements, _this);
              var _pagerLinks = jQuery(_options.pagerLinks, _this);
              var _btnPrev = jQuery(_options.btnPrev, _this);
              var _btnNext = jQuery(_options.btnNext, _this);
              var _btnPlayPause = jQuery(_options.btnPlayPause, _this);
              var _btnPause = jQuery(_options.btnPause, _this);
              var _btnPlay = jQuery(_options.btnPlay, _this);
              var _pauseOnHover = _options.pauseOnHover;
              var _autoRotation = _options.autoRotation;
              var _activeClass = _options.activeClass;
              var _disabledClass = _options.disabledClass;
              var _pausedClass = _options.pausedClass;
              var _playClass = _options.playClass;
              var _autoHeight = _options.autoHeight;
              var _duration = _options.duration;
              var _switchTime = _options.switchTime;
              var _controlEvent = _options.event;
              var _currentNum = (_options.currentNum ? jQuery(_options.currentNum, _this) : false);
              var _allNum = (_options.allNum ? jQuery(_options.allNum, _this) : false);
              var _startSlide = _options.startSlide;
              var _noCycle = _options.noCircle;
              var _onChange = _options.onChange;
              var _scrollGallery = _options.scrollGallery;

              // gallery init
              var _hover = false;
              var _prevIndex = 0;
              var _currentIndex = 0;
              var _slideCount = _slides.length;
              var _timer;
              if (_slideCount < 2) return;

              _prevIndex = _slides.index(_slides.filter('.' + _activeClass));
              if (_prevIndex < 0) _prevIndex = _currentIndex = 0;
              else _currentIndex = _prevIndex;
              if (_startSlide != null) {
                  if (_startSlide == 'random') _prevIndex = _currentIndex = Math.floor(Math.random() * _slideCount);
                  else _prevIndex = _currentIndex = parseInt(_startSlide);
              }
              _slides.hide().eq(_currentIndex).show();
              if (_autoRotation) _this.removeClass(_pausedClass).addClass(_playClass);
              else _this.removeClass(_playClass).addClass(_pausedClass);

              // gallery control
              if (_btnPrev.length) {
                  _btnPrev.bind(_controlEvent, function () {
                      prevSlide();
                      return false;
                  });
              }
              if (_btnNext.length) {
                  _btnNext.bind(_controlEvent, function () {
                      nextSlide();
                      return false;
                  });
              }
              if (_pagerLinks.length) {
                  _pagerLinks.each(function (_ind) {
                      jQuery(this).bind(_controlEvent, function () {
                          if (_currentIndex != _ind) {
                              _prevIndex = _currentIndex;
                              _currentIndex = _ind;
                              switchSlide();
                          }
                          return false;
                      });
                  });
              }

              // play pause section
              if (_btnPlayPause.length) {
                  _btnPlayPause.bind(_controlEvent, function () {
                      if (_this.hasClass(_pausedClass)) {
                          _this.removeClass(_pausedClass).addClass(_playClass);
                          _autoRotation = true;
                          autoSlide();
                      } else {
                          _autoRotation = false;
                          if (_timer) clearTimeout(_timer);
                          _this.removeClass(_playClass).addClass(_pausedClass);
                      }
                      return false;
                  });
              }
              if (_btnPlay.length) {
                  _btnPlay.bind(_controlEvent, function () {
                      _this.removeClass(_pausedClass).addClass(_playClass);
                      _autoRotation = true;
                      autoSlide();
                      return false;
                  });
              }
              if (_btnPause.length) {
                  _btnPause.bind(_controlEvent, function () {
                      _autoRotation = false;
                      if (_timer) clearTimeout(_timer);
                      _this.removeClass(_playClass).addClass(_pausedClass);
                      return false;
                  });
              }

              // gallery animation
              function prevSlide() {
                  _prevIndex = _currentIndex;
                  if (_currentIndex > 0) _currentIndex--;
                  else {
                      if (_noCycle) return;
                      else _currentIndex = _slideCount - 1;
                  }
                  switchSlide();
              }
              function nextSlide() {
                  _prevIndex = _currentIndex;
                  if (_currentIndex < _slideCount - 1) _currentIndex++;
                  else {
                      if (_noCycle) return;
                      else _currentIndex = 0;
                  }
                  switchSlide();
              }
              function refreshStatus() {
                  if (_pagerLinks.length) _pagerLinks.removeClass(_activeClass).eq(_currentIndex).addClass(_activeClass);
                  if (_currentNum) _currentNum.text(_currentIndex + 1);
                  if (_allNum) _allNum.text(_slideCount);
                  _slides.eq(_prevIndex).removeClass(_activeClass);
                  _slides.eq(_currentIndex).addClass(_activeClass);
                  if (_noCycle) {
                      if (_btnPrev.length) {
                          if (_currentIndex == 0) _btnPrev.addClass(_disabledClass);
                          else _btnPrev.removeClass(_disabledClass);
                      }
                      if (_btnNext.length) {
                          if (_currentIndex == _slideCount - 1) _btnNext.addClass(_disabledClass);
                          else _btnNext.removeClass(_disabledClass);
                      }
                  }
                  if (typeof _onChange === 'function') {
                      _onChange(_this, _currentIndex);
                  }
              }
              function switchSlide() {
                  _slides.eq(_prevIndex).fadeOut(_duration);
                  _slides.eq(_currentIndex).fadeIn(_duration);
                  if (_autoHeight) _slides.eq(_currentIndex).parent().animate({ height: _slides.eq(_currentIndex).outerHeight(true) }, { duration: _duration, queue: false });
                  refreshStatus();
                  autoSlide();
              }

              // autoslide function
              function autoSlide() {
                  if (!_autoRotation || _hover) return;
                  if (_timer) clearTimeout(_timer);
                  _timer = setTimeout(nextSlide, _switchTime + _duration);
              }
              if (_pauseOnHover) {
                  _this.hover(function () {
                      _hover = true;
                      if (_timer) clearTimeout(_timer);
                  }, function () {
                      _hover = false;
                      autoSlide();
                  });
              }
              refreshStatus();
              autoSlide();
          });
      }
