var Site={
    init:function(){
        $(document.body).addClass("js");
        if(window.webkit){
            $("s").type="search";
        }
        Site.splashGallery();
        Site.accordeon();
        Site.news();
        Site.wtf();
        Site.interval = Site.timer.periodical(5000);
        if($$("#glr a").length) $$("#glr a")[0].addClass("act");

        $$(".hentry img").each(function(img, i){
            var wrap = new Element("span", {"class":"imgwrap"})
            wrap.wraps(img)
            wrap.adopt(new Element("span", {"html":img.alt}))
        });
    },

    wtf:function(){
        if($$(".index").length) return;
        var ul = new Element("ul", {"id":"nav_wtf"});
        for(var i = 0;i<4;i++){
            ul.adopt(new Element("li",{"id":"li"+i}))
        }
        $("top").adopt(ul);
        ul.style.width = $("top").offsetWidth - 75 + "px";

        $$("#nav li").each(function(el,i){
            el.addEvent("mouseover",function(){
                if(i==0||i%4==0) $("li0").addClass("act");
                if(i==1||i%4==1) $("li1").addClass("act");
                if(i==2||i%4==2) $("li2").addClass("act");
                if(i==3||i%4==3) $("li3").addClass("act");
            });
            el.addEvent("mouseout", function(){
                $$("#nav_wtf li").each(function(li,k){
                    li.removeClass("act");
                });
            })
        });

    },

    splashGallery:function(){
        if(!$$(".index").length) return;
        var imgs = new Asset.images(["p/sp1.png", "p/sp2.png", "p/sp3.png"], {
            onComplete:function(){
                //alert('yo');
            }
        });

        $$(".index #splash .inner")[0].adopt(new Element("ul", {"id":"glr"}));
        var pics = ['pic0', 'pic1', 'pic2'];
        pics.each(function(pic,i){
            var li = new Element("li");
            var a = new Element("a", {'href':'#', 'id':pic, "html":"&nbsp;&nbsp;"});
            a.addEvent("click", function(e){
                var e = new Event(e);
                e.stop();
                $$("#glr a").each(function(el,k){el.removeClass("act");});
                $$("h1.decorate").each(function(el,i){el.removeClass("act");});
                $("pic").className = this.id;
                var num = this.id.replace('pic','');
                $$("#h"+num).addClass("act");
                this.addClass("act");
                Site.interval = $clear(Site.interval);
            })
            li.adopt(a)
            $("glr").adopt(li)
        });
    },

    counter:0,

    timer:function(){
        if(!$$(".index").length) return;
        $$("h1.decorate").each(function(el, i){el.removeClass("act");});
        $$("#glr a").each(function(el,k){el.removeClass("act");});
        $$("#h"+Site.counter+", #pic"+Site.counter).each(function(el,i){el.addClass("act")});
        $("pic").className = "pic" + Site.counter;
        Site.counter = (Site.counter==2)?0:Site.counter+1;
    },


    accordeon:function(){
        var myAccordion = new Accordion($('accordion'), $$("#faq h2 span"), '.slide', {
            opacity: false,
            onActive: function(toggler, element){
                toggler.setStyles({'border':'none', font:'30px/32px "times new roman"'});
            },
            onBackground: function(toggler, element){
                toggler.setStyles({'border-bottom':'2px dashed #046993', font:'20px/26px "times new roman"'});
            }
        });
    },

    defaults:function(els, values){
        $$(els).each(function(el, i){
            try{$$("label[for='"+el.id+"']")[0].remove()}catch(e){}
            el.value=values[i];
            el.addEvent("focus", function(){
                this.value=(this.value==values[i])?"":this.value;
                this.select();
            });
            el.addEvent("blur", function(){
                this.value=(this.value=="")?values[i]:this.value;
            });
        });
    },

    news:function(){
        var lis = $$(".index .news li");
        var lip = $$(".index .posts li");
        var ul = new Element("ul", {"id":"news_wtf"})
        lis.each(function(el,i){
            ul.adopt(new Element("li").adopt(new Element("a", {"href":"#", "id":i, "class":(i==0)?"act":""}).addEvent("click", function(e){
                var e = new Event(e);
                e.stop();
                $$("#news_wtf a").each(function(a, h){a.removeClass("act")})
                lis.each(function(li,k){li.removeClass("hot")})
                lip.each(function(li,k){li.removeClass("phot")})
                lis[this.id].addClass("hot");
                lip[this.id].addClass("phot");
                this.addClass("act");
                })
            ))
        })
        $$(".index .news")[0].getParent().adopt(ul);

    }
}


window.addEvent("domready", Site.init);

window.addEvent("load", function(){
    if(!$("img")) return;
    $$("#img")[0].style.width = $$("#img img")[0].offsetWidth + "px";

    $("img").addEvent("mouseover", function(){
        this.addClass("hover");
    })
    $("img").addEvent("mouseout", function(){
        this.removeClass("hover");
    })
});


