Function.prototype.bind = function (e, d) {
    var a = d || [];
    var b = this;
    return function () {
        var f = [];
        $(arguments).each(function (g, h) {
            f.push(h)
        });
        $(a).each(function (g, h) {
            f.push(h)
        });
        return b.apply(e, f)
    }
};
String.prototype.dasherize = function () {
    return this.replace(/_/g, "-")
};
String.prototype.underscore = function () {
    return this.replace(/-/g, "_")
};

var P = (function (b, a) {
    a.el = function (d) {
        return b("#" + d)[0]
    };
    a.setUrlHash = function (d) {
        window.location = d
    };
    return a
})(jQuery, P || {});
var P = (function (a) {
    a.Location = {
        lastPath: null,
        chromeFirstPopStateCall: false,
        useHistory: false,
        init: function () {
            this.startingPath = window.location.pathname;
            this.useHistory = history.pushState && !$("html").hasClass("ipad");
            if (this.useHistory) {
                $(window).bind("popstate", this.popStateHandler.bind(this))
            } else {
                $(window).bind("hashchange", this.hashChangeHandler.bind(this))
            }
        },
        hashChangeHandler: function (b) {
            var d = window.location.hash.replace(/^#(!)?/, "");
            if (d !== this.lastPath) {
                a.Window.openOrGiveFocus(d)
            }
        },
        set: function (d, b, h) {
            d = d.replace(/\/index\/?$/, "");
            var f = d.replace(/^http(s)?:\/\/[^\/]+\//, "/");
            var g = f.split("?")[1];
            if (g) {
                var e = f.split("?")[0];
                e = e.dasherize();
                f = e + "?" + g
            } else {
                f = f.dasherize()
            }
            if (this.useHistory) {
                f = f.slice(0, 1) === "/" ? f : "/" + f;
                history.pushState(b, h, f)
            } else {
                if (f.substring(0, 1) === "/") {
                    f = f.substring(1)
                }
                var j = f.split("/");
                j.shift();
                f = "/" + j.join("/");
                window.location.hash = "!" + f
            }
            this.lastPath = f
        },
        popStateHandler: function (b) {
            if (/chrome/.test(navigator.userAgent.toLowerCase()) && !this.chromeFirstPopStateCall) {
                this.chromeFirstPopStateCall = true;
                return true
            }
            var d = b.originalEvent.state && b.originalEvent.state.path ? b.originalEvent.state.path : this.startingPath;
            a.Window.openOrGiveFocus(d, {
                disablePushState: true
            })
        },
        isLanguagePage: function () {
            regexp = new RegExp("^/?(" + a.app.availableLocales + ")/?$");
            if (new RegExp("^(#!/)?$").test(window.location.hash) || (new RegExp("^#!(" + a.app.availableLocales + ")/?$")).test(window.location.hash)) {
                return regexp.test(window.location.pathname)
            } else {
                return false
            }
        },
        isHomepage: function () {
            return window.location.pathname == "/"
        }
    };
    return a
})(P || {});
(function (b) {
    var a = function (f) {
            var e = b(this),
                d = e.siblings("ul");
            e.parent().toggleClass("expanded");
            if (e.data("target") == "toggle") {
                if (d.is(":visible")) {
                    d.find("ul").hide()
                }
                return false
            }
        };
    b(".accordion-menu [data-target=toggle]").live("click", a)
})(jQuery);

var P = (function (b, a) {
    a.initApp = function () {
        var d = new a.App();
        a.app = d;
        d.init()
    };
    a.App = function () {};
    a.App.OSData = [{
        string: navigator.platform,
        subString: "Win",
        identity: "win"
    }, {
        string: navigator.platform,
        subString: "Mac",
        identity: "Mac"
    }, {
        string: navigator.userAgent,
        subString: "iPhone",
        identity: "iPhone/iPod"
    }, {
        string: navigator.userAgent,
        subString: "iPad",
        identity: "iPad"
    }, {
        string: navigator.platform,
        subString: "Linux",
        identity: "Linux"
    }];
    a.App.clickEvent = Modernizr.touch ? "touchstart" : "click";
    a.App.prototype.init = function () {
        a.Location.init();
        this.osClass = this.getOSClass(a.App.OSData);
        this.initWallpaper();
        if (this.osClass) {
            b("html").addClass("os-" + this.osClass.toString().toLowerCase())
        }
    };
    a.App.prototype.getOSClass = function (g) {
        for (var d = 0; d < g.length; d++) {
            var e = g[d].string;
            var f = g[d].prop;
            this.versionSearchString = g[d].versionSearch || g[d].identity;
            if (e) {
                if (e.indexOf(g[d].subString) != -1) {
                    return g[d].identity
                }
            } else {
                if (f) {
                    return g[d].identity
                }
            }
        }
    };
    a.App.prototype.initWallpaper = function () {
		if(a.el("wallpaper")){
        this.wallpaper = new a.Wallpaper(a.el("wallpaper"));
        this.wallpaper.init();
		}
    };
    return a
})(jQuery, P || {});
var P = (function (d, b) {
    var a = {
        images: [],
        completed: true,
        callbacks: {
            step: function () {}
        }
    };
    b.Preloader = function (e) {
        d.extend(this, a, e);
        if (this.images.length > 0) {
            this.completed = false
        }
        this.images = d.map(e.images, function (f) {
            return {
                src: f
            }
        })
    };
    b.Preloader.prototype.init = function (e) {
        if (!this.completed) {
            this.go({
                callback: e ||
                function () {}
            })
        }
    };
    b.Preloader.prototype.go = function (g) {
        var f = this.images,
            e = this;
        (function (k) {
            var h = 0;

            function j(l, m) {
                m.onload = function (n) {
                    h++;
                    f[l].width = m.width;
                    f[l].height = m.height;
                    e.callbacks.step({
                        index: l,
                        image: f[l]
                    });
                    if (h == f.length) {
                        k()
                    }
                };
                m.src = f[l].src;
                if (l + 1 < f.length) {
                    j(l + 1, new Image())
                }
            }
            j(0, new Image())
        })(g.callback)
    };
    return b
})(jQuery, P || {});
var P = (function (b, a) {	
	var opt = {
		current : 0
	}
    b.fn.setAsWallpaperImage = function (d) {
       // if (Modernizr.touch) {
       //     a.app.wallpaper.setIpadWallpaper(a.app.wallpaper.currentPath)
      //  } else {
            b(this).css({
                display: "none"
            }).appendTo(b(a.app.wallpaper.element)).fadeIn(2500);
            if (d) {
                d()
            }
       // }
    };
    a.Wallpaper = function (d) {
        this.element = d;
        b(this.element).mousedown(function (e) {
            e.preventDefault()
        });
        //if (Modernizr.touch) {
         //   b(this.element).hide()
        //}
    };
    a.Wallpaper.prototype.init = function () {
        this.images = {};
		this.imageslist       = Array();
		this.timeoout         = '';
		this.handle           = b("#handle");		
		this.playHandle       = b("#playHandle");
		this.introHandle      = b("#introHandle");
		this.itemIntro        = b("#itemIntro");
		this.photographer     = b("#photographer");
		this.photographerlist = Array();
		this.currentImg = 0;
		b(this.element).children("img").each(function(){
			b(this).css({display:"none"});
			a.app.wallpaper.imageslist.push({'src':this.src});
			a.app.wallpaper.photographerlist[this.src] = this.alt;
		});
		this.handle.children("li").each(function(){
			bm = b(this);
			bm.click(function(){
				clearTimeout(a.app.wallpaper.timeout);
				
				var h = $('#playHandle');
				if(h.hasClass("play")){						
					h.removeClass("play").addClass("pause");
				}
				bt = b(this);
				opt.current = bt.text()-1;
				a.app.wallpaper.show(a.app.wallpaper.imageslist[opt.current].src);
			});	
		})
		b(this.playHandle).addClass("pause");

//		this.introHandle.click(function(){
//			var o = $('#itemIntro');
//			var h = $('#playHandle');
//			if(o.hasClass("hidden")){					
//				o.css({'z-index':'10'});
//				o.removeClass("hidden").fadeIn(700).addClass("show");
//				clearTimeout(a.app.wallpaper.timeout);
//				h.removeClass("pause").addClass("play");
//			}else{	
//				o.removeClass("show").fadeOut(700).addClass("hidden");
//				a.app.wallpaper.show(a.app.wallpaper.imageslist[opt.current].src);
//				h.removeClass("play").addClass("pause");	
//			}
//		})
		this.introHandle.click(function(){
			var o = $('#itemIntro');
			var h = $('#playHandle');
			if(!(o.hasClass("show"))){					
				o.css({'z-index':'10'});
				o.removeClass("hidden").fadeIn(700).addClass("show");
				clearTimeout(a.app.wallpaper.timeout);
				h.removeClass("pause").addClass("play");
			}
		})
		this.playHandle.click(function(){
			var h = $('#playHandle');
			if(h.hasClass("play")){	
				a.app.wallpaper.show(a.app.wallpaper.imageslist[opt.current].src);
				h.removeClass("play").addClass("pause");
			}else if(h.hasClass("pause")){		
				clearTimeout(a.app.wallpaper.timeout);
				h.removeClass("pause").addClass("play");
			}
		})
		this.itemIntro.children("a.close").each(function(){
			b(this).click(function(){				
				var o = $('#itemIntro');
				var h = $('#playHandle');
				if(!(o.hasClass("hidden"))){
					o.removeClass("show").fadeOut(700).addClass("hidden");
					if(h.hasClass("play")){						
						a.app.wallpaper.show(a.app.wallpaper.imageslist[opt.current].src);
						h.removeClass("play").addClass("pause");
					}
				}
			})

		})
        this.defaultPath = this.imageslist[0].src;
        this.currentPath = null;
        if (this.defaultPath) {
            this.show(this.defaultPath)
        }
    };
    a.Wallpaper.prototype.setIpadWallpaper = function (f) {
        var d = f.lastIndexOf("."),
            e = f.slice(0, d),
            g = f.slice(d);
       // b("body").css("background", "url(" + e + "_ipad" + g + ") no-repeat 0 0")
	    b("#wallpaper").css("background", "url(" + f + ") no-repeat 0 0")
    };
    a.Wallpaper.prototype.show = function (e, f) {
        if (!e) {
            return
        }

        if (this.currentPath !== e) {	
			if(this.images[this.currentPath]){
				b(this.images[this.currentPath]).fadeOut(750);
			}
            this.currentPath = e;
            var d = this.images[e] || new Image();
            if (!d.src) {
                d.src = e;
                b(d).hide().appendTo(b(this.element));
                b(d).bind("load", this.imageLoadHandler.bind(this, [f]));
                if (d.complete && (b("html").hasClass("ie7") || b("html").hasClass("ie8"))) {
                    this.imageLoadHandler(d, f)
                }
                this.images[e] = d
            } else {						 
                b(d).setAsWallpaperImage(f)
            }
			this.photographer.text(a.app.wallpaper.photographerlist[this.currentPath])
			this.handle.children("li").each(function(){
				bm = b(this);
				//if(bm.text() == opt.current+1){
				if(a.app.wallpaper.imageslist[bm.text()-1].src == e){
					bm.addClass("active");
				}else{
					bm.removeClass("active");
				}
			})
			this.timeout = setTimeout(function(){
				a.app.wallpaper.show(a.app.wallpaper.imageslist[opt.current].src)
			},5000);				
			
			opt.current = opt.current + 1;
			if(opt.current == this.imageslist.length){
				opt.current = 0;
			}
        }
    };
    a.Wallpaper.prototype.revert = function (e) {
        if (e) {
            if (Modernizr.touch) {
                this.setIpadWallpaper(this.defaultPath);
                this.currentPath = this.defaultPath
            } else {
                var d = this.images[this.defaultPath];
                if (d && this.defaultPath !== e) {
                    this.show(this.defaultPath)
                }
            }
        }
    };
    a.Wallpaper.prototype.imageLoadHandler = function (d, e) {
        if (d.target) {
            $wallImage = b(d.target)
        } else {
            $wallImage = b(d)
        }
        $wallImage.setAsWallpaperImage(e);
        this.resize()
    };
    a.Wallpaper.prototype.resize = function () {
       // if (Modernizr.touch) {
       //     return
       // }
        var h, f, g, d;
        var j = b("body");
        var k = b(this.element);
		if(b('body').hasClass("homepage")){
			k = b(window);
			b(this.element).css("width",k.width());
			b(this.element).css("height",k.height());
		}
        var e = b(this.element).children("img").last();
        b(window).resize(function () {
            g = e.width();
            d = e.height();
            if (k.width() > k.height()) {
                if (g > d) {
                    h = g / d;
                    f = Math.round(k.width() * (1 / h));
                    e.css("width", k.width() + "px");
                    e.css("height", f);
                    if (f < k.height()) {
                        h = d / g;
                        e.css("height", k.height());
                        e.css("width", Math.round(k.height() * (1 / h)))
                    }
                } else {
                    h = d / g;
                    e.css("height", k.height());
                    e.css("width", Math.round(k.height() * (1 / h)))
                }
            } else {
                h = d / g;
                e.css("height", k.height());
                e.css("width", Math.round(k.height() * (1 / h)))
            }
        }).trigger("resize")
    };
    return a
})(jQuery, P || {});
var P = (function (b, a) {
    a.Scrollpane = {};
    a.Scrollpane.initWithin = function (d) {
        b("[data-scrollpane]", d).each(function (f, h) {
            $element = b(h);
            var g = ($element.data("scrollpane") === "arrows" ? {
                showArrows: true
            } : {});
            $element.jScrollPane(g)
        })
    };
    return a
})(jQuery, P || {});

(function (b, a) {
    b(function () {
        a.initApp()
    });
    return a
})(jQuery, P);
$(function () {
    if (navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i)) {
        var b = document.querySelector('meta[name="viewport"]'),
            a = "width=device-width, minimum-scale=1.0, maximum-scale=1.0, initial-scale=1.0";
        if (b) {
            b.content = a;
            document.body.addEventListener("gesturestart", function () {
                b.content = "width=device-width, minimum-scale=0.25, maximum-scale=2.0, initial-scale=1.0"
            }, false);
            window.onorientationchange = function () {
                b.content = a
            }
        }
    }
});
$(function(){
   function windowalign(){
		var bodyheight = $(document).height();
		bodywidth = $(window).width();
		wrapwidth = $("#wrapper").width()+34;		
		wrapheight = $("#wrapper").height()+32; 
		postop = (bodyheight-wrapheight)/2;  
		posleft = (bodywidth-wrapwidth)/2;  
		$("#wrapper").css({"left":posleft+"px",
						   "top":postop+"px",
						   "position":"absolute"}); 
	}
	windowalign();
	$(window).resize(function(){  
		windowalign();
	});
})
//function swich(obj){
//	var o = $('#'+obj);
//	if(o.hasClass("show")){	
//		o.removeClass("show").fadeOut(700).addClass("hidden");
//	}else{		
//		o.css({'z-index':'10'});
//		o.removeClass("hidden").fadeIn(700).addClass("show");
//	}
//}
function swich(obj){
	var o = $('#'+obj);
	if(!(o.hasClass("show"))){	
		o.removeClass("hidden").fadeIn(700).addClass("show");
	}
}
function hide(obj){
	var o = $('#'+obj);
	if(!(o.hasClass("hidden"))){	
		o.removeClass("show").fadeOut(700).addClass("hidden");
	}
}
