// JavaScript Document 
// Sitewide Javascript for cueartfoundation.org
// (c)2009 stevesunderland
// version 2.0
// last revision 041209

var Site = {

    begin: function() {
        Site.navigation();
        //Site.tips();
        //new SmoothScroll({ duration:700 }, window);
        //Site.fontsizes();
        Site.homeslider();
        Site.supporthover();
        Site.footer();
        if ($('featurespan')) Site.featurehover();
		if ($('tagcloud')) Site.tagcloud(); 
		
		//$$('.smallfont').addEvent('click', function() {Site.fontsizes(-1);});	         			  
		//$$('.bigfont').addEvent('click', function() {Site.fontsizes(5);});
    },              

	tagcloud: function() {  
		
		var ticks = $$('div.tagcloud span');
		ticks.set('morph', {unit: 'em'});
    	ticks.morph('.tagspannormal');
		ticks.each(function(t){
			t.addEvent('mouseenter', function(){ 
				this.set('morph', {unit: 'em'});
				this.morph('.tagspanhover');
			}); 
			t.addEvent('mouseleave', function(){
				this.set('morph', {unit: 'em'});
				this.morph('.tagspannormal');
			});
		}); 
		
		var clicks = $$('div.tagcloud a');
    	clicks.morph('.tagnormal');
		clicks.each(function(c){
			c.addEvent('mouseenter', function(){ 
				this.morph('.taghover');
			}); 
			c.addEvent('mouseleave', function(){
				this.morph('.tagnormal');
			});
		});
	},

    navigation: function() {  
	    
		$('nav_wrapper').set('tween', {link: 'ignore'});
		$('nav_wrapper').tween('height', 32);
        
	
        $('nav').addEvent('mouseenter',
        function() {        
            $('nav_wrapper').tween('height', [32, 160]);
        });

        $('nav_wrapper').addEvent('mouseleave',
        function() {
            $('nav_wrapper').tween('height', [160, 32]);
        });

    },

    drag: function() {
        var drag = $$('picture').makeDraggable();
    },

    tips: function() {
        var myTips = new Tips('.thumbnail');

        myTips.addEvent('show',
        function(tip) {
            tip.fade('in');
        });

        myTips.addEvent('hide',
        function(tip) {
            tip.fade('out');
        });
    },

    fontsizes: function(multiplier) {

        var fontsz = '.75em';
        //Default to 1em
        if (Cookie.read('fontsize'))
        {
            // Use MooTools to get the cookie (if it exists)
            fontsz = Cookie.read('fontsize');
        }
        fontsz = parseFloat(fontsz)+(multiplier * 0.2)+'em';
        //set up morph         

//		var fs = $$('#content_inner p'); 
				
        var morphTextSize = new Fx.Morph('content_inner', {
            duration: 300,
            transition: Fx.Transitions.linear,
            unit: 'em'
        });

        //set font size
        morphTextSize.start({
            'font-size': parseFloat(fontsz)+(multiplier * 0.2)
        });
        //Set a new cookie with MooTools
        var myCookie = Cookie.write('fontsize', fontsz);

 //        $$('.smallfont').addEvent("click", function() {Site.fontsizes(-1);});
//         $$('.bigfont').addEvent("click", function() {Site.fontsizes(1);});
    },

    homeslider: function() {
        var accordion = new Accordion('h4.trigger', 'div.slider', {
            opacity: false,
            duration: 500,
        },
        $('accordion'));

        accordion.togglers.each(function(toggler) {
            toggler.addEvent('mouseover',
            function() {
                this.fireEvent('click');
            });
        });
    },

    featurehover: function() {
        var featurespan = $$('#featurespan');
        var featurebox = $$('div#feature'); 

		featurespan.fade('hide');
		featurebox.addEvent('mouseenter', function() {
			featurespan.fade('in');
		});
		
		featurebox.addEvent('mouseleave', function() {
			featurespan.fade('out');
		});
       
    },

    supporthover: function() {
        var supportbox = $$('.ditto_support');
        supportbox.tween('background-color', '#ffffff');
        supportbox.each(function(element) {

            element.addEvent('mouseenter',
            function(e) {
				var current = $$('h2').getStyle('color');
                this.tween('background-color', current);
            });

            element.addEvent('mouseleave',
            function(e) {
                this.tween('background-color', '#ffffff');
            });
        });
    },

    footer: function() {
	    //initialize
		$('search').tween('width', 80);
		$('text').tween('width', 100);
        //search 
        $('search').addEvent('mouseenter',
        function() {
            $('search').tween('width', 310);
        });

        $('search').addEvent('mouseleave',
        function() {
            $('search').tween('width', 80);
        });
        //text 
        $('text').addEvent('mouseenter',
        function() {
            $('text').tween('width', 275);
        });
        $('text').addEvent('mouseleave',
        function() {
            $('text').tween('width', 100);
        });
    }
}

window.addEvent('domready', Site.begin);