var engine = {
    pageTools : {
        init : function() {
            $j("#font_select").click(function(){
                engine.pageTools.animateContentFontSize(12)
            });
            $j("#font_select_med").click(function(){
                engine.pageTools.animateContentFontSize(15)
            });
            $j("#font_select_large").click(function(){
                engine.pageTools.animateContentFontSize(20)
            });        
        },
        animateContentFontSize : function(s){
            $j("#contentHere").stop().animate({
                fontSize: s+"px"
            }, 300 )
        }
    },
    externalLinks : function(){
        $j('a:external').addClass('external');
        $j('a.external').click(function() {
            var link = $j(this).attr('href');
            window.open(link);
            return false;
        });
    },
    tabClick : {
        init : function(opts){
            if ($j("ul.tab").length) {
                $j("ul.tab:first").fadeIn(1000);
                $j("ul.tab li:last-child").css({"border":"none"});
                if($j("#tabs:visible").length) {
                    $j(opts.navigation).click(function(){
                        opts.tabNumber = $j(this).getIndex();
                        engine.tabClick.loadContent(opts);
                        return false;
                    })
                }
            }

        },
        markSelected : function(opts){
            var $old = $j(opts.navigation + ":not(:eq("+opts.tabNumber+")) a.selected");
            var $new = $j(opts.navigation + ":eq("+opts.tabNumber+") a:not(.selected)");
            $old.removeClass("selected");
            $new.addClass("selected")
        },
        loadContent : function(opts){
            $j(opts.tabs + ":not(:eq("+opts.tabNumber+"))").hide();
            $j(opts.tabs + ":eq("+opts.tabNumber+")").fadeIn(300);
            engine.tabClick.markSelected(opts);
        },
        animateArrow : {
            left : function(e) {
                $j(e).stop().animate({
                    backgroundPosition:"(600px 50%)"
                },300)
            },
            right : function(e) {
                $j(e).stop().animate({
                    backgroundPosition:"(610px 50%)"
                },300)
            }
        }
    },
    structure: {
        init : function(){
            if (!jQuery.support.opacity) {
                this.ie();
                this.allBrowsers();
            }
            else {
                this.allBrowsers();
            }
        },
        ie : function(){
            $j("div.sidebar ul li:last-child, #tabs li:last-child a").css("border","none");
        },
        allBrowsers : function(){
            $j("ul.sf-menu").supersubs({
                minWidth:12,
                maxWidth:27,
                extraWidth:1
            }).superfish().find('ul').bgIframe({
                opacity:false
            });
            $j("ul.sf-menu>li li:last-child").css("border","none")
            $j("ul.slides").cycle({
                fx: 'fade',
                timeout: 9000,
                pause: 1,
                containerResize: 1,
                cleartypeNoBg:   true
            });
            $j("#footermenu .donate img, #Contribute, #Volunteer").fadingButton(300,0.8);
            $j("#footermenu a:not(.donate)").hover(function(){
                $j(this).stop().animate({
                    "left":5,
                    "color":"#333"
                },100)
            }, function(){
                $j(this).stop().animate({
                    "left":0,
                    "color":"#666"
                },200)
            });
            $j("#searchButton input, input.submit_tag, input.submit_button").button();
            $j("#blog-comments input:submit, table.styled_table input:submit, #contribute_submit_button").button();
            $j("#menu").delegate("a[href='/Meet-Lisa'], a[href='/Newsroom']","click",function(e){e.preventDefault()})
            $j("table.styled_table select:contains(Il)").val("IL")

        }
    }
}

$j(function(){
    $j.fn.formLables();
    engine.structure.init();
    engine.externalLinks();
    engine.pageTools.init();
    engine.tabClick.init({
        navigation:"#tabs li",
        tabs:"ul.tab"
    });
});
