var touch = false;
var mobile = (/iphone|ipad|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()));  
    if (mobile) {  
        touch = true;
    }  else {
    	touch = false;
    }


function makedragger(a, b) {
    (function (a) {
        function c(b) {
            var c = b || window.event,
                d = [].slice.call(arguments, 1),
                e = 0,
                f = true,
                g = 0,
                h = 0;
            b = a.event.fix(c);
            b.type = "mousewheel";
            if (b.wheelDelta) {
                e = b.wheelDelta / 120
            }
            if (b.detail) {
                e = -b.detail / 3
            }
            h = e;
            if (c.axis !== undefined && c.axis === c.HORIZONTAL_AXIS) {
                h = 0;
                g = -1 * e
            }
            if (c.wheelDeltaY !== undefined) {
                h = c.wheelDeltaY / 120
            }
            if (c.wheelDeltaX !== undefined) {
                g = -1 * c.wheelDeltaX / 120
            }
            d.unshift(b, e, g, h);
            return a.event.handle.apply(this, d)
        }
        var b = ["DOMMouseScroll", "mousewheel"];
        a.event.special.mousewheel = {
            setup: function () {
                if (this.addEventListener) {
                    for (var a = b.length; a;) {
                        this.addEventListener(b[--a], c, false)
                    }
                } else {
                    this.onmousewheel = c
                }
            },
            teardown: function () {
                if (this.removeEventListener) {
                    for (var a = b.length; a;) {
                        this.removeEventListener(b[--a], c, false)
                    }
                } else {
                    this.onmousewheel = null
                }
            }
        };
        a.fn.extend({
            mousewheel: function (a) {
                return a ? this.bind("mousewheel", a) : this.trigger("mousewheel")
            },
            unmousewheel: function (a) {
                return this.unbind("mousewheel", a)
            }
        })
    })(jQuery);
    var c = {
        blogsData: {},
        currentHash: "",
        currentTitle: "",
        firstLoad: true,
        ignoreHashChange: false,
        isTouch: touch,
        messageTimeout: 0,
        scrollDirection: -1,
        scrollToTarget: null,
        scrollXEaseInterval: 0,
        scrollXFirstChild: null,
        scrollXHandleOffset: 0,
        scrollXHandleStart: 0,
        scrollXLastChildMoving: null,
        scrollXLastChildSteps: 0,
        scrollXMax: 0,
        scrollXSitesStart: 0,
        scrollXSpeed: 0,
        scrollXStart: 0,
        scrollXTick: 0,
        scrollXTrackOffset: 0,
        siteWidth: 0,
        ready: function () {
        
        
        
        
            c.applyScrollingX()
        },
        
  
                
        
        initStateResizes: function () {
            $(b).width($(window).width() - $(b).offset().left + "px")
        },
        applyScrollingX: function () {
            if (!c.isTouch) {
                $(a).show();
                $(a).draggable("destroy").draggable({
                    axis: "x",
                    containment: ".drag_holder",
                    start: function () {
                        $(document).unbind("mouseup", c.resetScrollerX).mouseup(c.resetScrollerX)
                    },
                    drag: function (a, b) {
                        c.scrollX();
                      
                    },
                    stop: function () {
                        $(a).animate({
                            left: "0"
                        }, 1e3);
                        c.stopScrollX;
                        var d = $(b).position().left;
                        if (b == "#area1 .container") {}
                        if (b == "#area2 .container") {}
                        if (b == "#area3 .container") {};
                    }
                });

                $(window).unbind("resize", c.centerScrollerX).resize(c.centerScrollerX)
            }
            $(document).unbind("keyup").keyup(c.handleKeyboard);
            $(window).unbind("resize", c.applyScrollingXResize).resize(c.applyScrollingXResize);
            $(window).resize();
            c.applyScrollXForSites()
        },
        alignSites: function () {
            $(c.sites).each(function (a) {
                $(this).css("left", a * $(this).outerWidth() + "px")
            })
        },
        applyScrollingXResize: function () {
            c.sitesCentre = $(b).width() / -2 + $(b).offset().left
        },
        resetScrollerX: function (a) {
            clearInterval(c.scrollXTick);
            c.scrollXSpeed = c.scrollXSpeed > 0 ? 10 : c.scrollXSpeed < 0 ? -10 : 0;
            c.scrollXRound();
            c.centerScrollerX()
        },
        centerScrollerX: function () {
            var a = $(b).width() / 2
        },
      
        applyScrollXForSites: function () {
            if (c.isTouch) {
                //var a = $('#area1 .container');
                //a.removeEventListener("touchstart", c.scrollXDown);
                //a.addEventListener("touchstart", c.scrollXDown);
                
                
              
                
            } else {
                $(b).unbind("mousedown").mousedown(c.scrollXDown)
            }
            $(window).resize()
        },
       
        scrollXGetCoords: function (a) {
            var b;
            if (c.isTouch) {
                if (a.hasOwnProperty("originalEvent")) {
                    a = a.originalEvent
                }
                if (a.touches && a.touches.length) {
                    b = a.touches[0].clientX;
                    if (arguments[1]) {
                        a.preventDefault();
                    }
                }
            } else {
                a.preventDefault();
                b = a.clientX
            }
            return b
        },
        scrollXDown: function (a) {
            var d = c.scrollXGetCoords(a);
            c.scrollXStart = d;
            c.hideDragMessage();
            $(b).stop(true);
            if (c.scrollXEaseInterval) {
                clearInterval(c.scrollXEaseInterval)
            }
            if (c.isTouch) {
                
                  
                //var e = $(b);
            
                e.removeEventListener("touchmove", c.scrollXDrag);
                e.addEventListener("touchmove", c.scrollXDrag);
                e.removeEventListener("touchend", c.stopScrollX);
                e.addEventListener("touchend", c.stopScrollX)
            } else {
                $(b).unbind("mousemove", c.scrollXDrag).mousemove(c.scrollXDrag).unbind("mouseleave", c.stopScrollX).mouseleave(c.stopScrollX).unbind("mouseup", c.stopScrollX).mouseup(c.stopScrollX)
            }
        },
        scrollXDrag: function (a) {
            var b = c.scrollXGetCoords(a, true);
            c.scrollXSpeed = b - c.scrollXStart;
            c.scrollXDo(c.scrollXSpeed);
            c.scrollXStart = b;
            a.preventDefault()
        },
        scrollX: function () {
            clearInterval(c.scrollXTick);
            c.scrollXSpeed = -$(a).position().left;
            c.scrollXInterval();
            c.scrollXTick = setInterval(c.scrollXInterval, 13)
        },
        scrollXInterval: function () {
            var a = c.scrollXSpeed / 5;
            c.scrollXDo(a)
        },
        scrollXDo: function (a) {
            if ($(b).position().left >= 0) {
                $(b).css("left", "5px").stop(true, true)
            }
            if ($(b).position().left <= ($(b).width() - 500) * -1) {
                $(b).css("left", "0px")
            }
            $(b).stop(true).css({
                left: function (b, c) {
                    var d = Number(c.replace("px", "")) + a;
                    return d
                }
            })
        },
        scrollXRound: function () {
            if ($("body").hasClass("ie7") || $("body").hasClass("ie8")) {
                c.scrollXSpeed = 0;
                c.scrollXEaseDo()
            } else {
                if (c.scrollXSpeed > 5 || c.scrollXSpeed < -5) {
                    c.scrollXSnap()
                } else {
                    c.scrollXSpeed = 0
                }
            }
        },
        scrollXSnap: function () {
            var a = $(b).position().left;
            var d = a + c.scrollXSpeed;
            var e = Math.round(d / c.siteWidth) * c.siteWidth;
            var f = e - d;
            if (f < c.siteSnapMargin && f > -c.siteSnapMargin) {
                d = e
            }
            if (arguments[0] === true) {
                d = e
            }
            $(b).animate({
                left: d
            }, "slow", "easeOutQuint", 2e3);
            c.scrollXSpeed = 0
        },
        stopScrollX: function () {
            if (c.isTouch) {
                var a = $(b);
                a.removeEventListener("touchmove", c.scrollXDrag);
                a.removeEventListener("touchend", c.stopScrollX)
            } else {
                $(b).unbind("mousemove").unbind("mouseup").unbind("mouseleave")
            }
            if (arguments[0] !== true) {
                c.scrollXRound()
            }
        },
        hideDragMessage: function () {
            clearTimeout(c.messageTimeout)
        }
    };
    $(document).ready(c.ready)
}

