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;
        });
    },
	
	  slideshow : function(){
        function onBefore(curr, prev, opts) {
            var currentSlide = $j(this).getIndex();
         
        }
        $j('#slides div.slide:first').fadeIn(1000, function() {
            $j('#slides').cycle({
                fx: 'fade',
                timeout: 5000,
                speed: 1000,
                pager:'#pager',
                pauseOnPagerHover: true,
                pause: 1,
                before: onBefore,
				next: '#next',
				prev: '#prev',
                pagerAnchorBuilder:function(idx,slide){
                    return'#pager li:eq(' + (idx) + ') a';
                }
			   
			   
            });
        });
    },
    tabClick : {
        init : function(opts){
            $j("#tabbedContent div.tab:first").fadeIn(300);
            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, function(){
                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(){
        //HERE GOES jQUERY FOR IE BROWSERS ONLY!
        },
        allBrowsers : function(){
            $j("img.fadingButton").fadingButton(300,0.7);
            $j("ul.sf-menu").supersubs({
                minWidth:12,
                maxWidth:27,
                extraWidth:1
            }).superfish().find('ul').bgIframe({
                opacity:false
            });
        }
    }
}




$j(function(){
    engine.structure.init();
	  engine.slideshow();
    engine.externalLinks();
    
    
    plugins.flickrFeed({      
        //cont: "#flickr",
        //api: "eb4be2bc9b39e0625af47006c9a790cc",
        //type: "set",
          type: "user",
        userId: "18851995@N02",
        num: 2
    });
	
	
    if ($j('#twitterFeed').length) {
        $j('#twitterFeed').twitterSearch({
            term: 'from%3ACAWorkingFams',		
            bird: false,		
            avatar: false,
            colorExterior: '#ddd',
            colorInterior: 'white',
            pause:   true,
            timeout: 3000
        });
        $j("a.tweet-this").tweetIt({
            typeATweet: "",
            header: "Send a tweet from here!"
        });
    }
	//$j("#ibfacebook div.widget-inner").facebookWidget({fans: 4, showTotalNumber: false, objectID: '113147562046000', likeLink: "#ibfacebook a:first"});
	
	

});


