var dlga =
{
	docRoot: null, // set the site root for ajax calls in the dlga class
	
	/*
	* Because we want to only load jquery tools AFTER the browser has already downloaded/rendered everything else, we'll pass
	* an array of the function names we want to load to the variable fireToolsFunctions. If this variable IS set, then we dynamically
	* load the jQueryTools script, and then in the callback function, pass an array of which functions we want to execute that require jqtools
	*/
	fireToolsFunctions: null,

	bells_whistles: {
		init: function(){
			
			if(!jQuery.browser.msie){ $('.box-shadow-fix').css({ 'border':'none','padding':'3px' }) } // aesthetic fix
			
			$(".frm-input").focus(function(){ $(this).val('').removeClass('greytext'); }) // auto remove text on form field focus
			
			if(dlga.fireToolsFunctions){
				$.getScript(dlga.docRoot+'jquery.tools.min.js',function(){ 
					$.each(dlga.fireToolsFunctions,function(k,v){ eval('dlga.'+v+'.init()') })
				})
			}
		}
	},

	
    /*****************************************************************
	* DEPENDENCY: jQuery
    * Main navigation menu setup
    *****************************************************************/	
	nav_menu: {
		init: function(){
			$('li','ul#navMenu').bind({
				mouseenter: function(){ $(this).find('.sub').css('display','block'); },
				mouseleave: function(){$(this).find('.sub').css('display','none'); }
			})
		}
	},

    /*****************************************************************
	* DEPENDENCY: jQuery
    * Sliding login panel setup
    *****************************************************************/
    sliding_panel: {
        init: function(){

            $(".login-input").focus(function(){ $(this).val('').removeClass('greytext'); })
            var tracker = false; // bool to see whether slider is open or closed
            $(".slider-toggle").click(function(){
                if(!tracker){
                    $(this).text("Hide");
                    tracker = true;
                }else{
                    $(this).text("Login");
                    tracker = false;
                }
                $("#panel").slideToggle("slow");
            });

        }
    },
	
    /*****************************************************************
	* DEPENDENCY: jQuery, jQueryTools
    * Homepage featured scroller (uses jqtools Scrollable plugin)
    * TODO: implement lazy loading of scrollable elements?
    *****************************************************************/
    scroller: {
        init: function(){

            var scroll = $("#scrollable").scrollable({
                size: 1,
                activeClass: "active",
                speed:550,
				circular:true,
                onSeek: function(e,index){
                    $("a.active", '#cScrollTrack ul li').removeClass("active");
                    $("a","#cScrollTrack ul li:eq("+index+")").addClass("active");
                }
            }).autoscroll({
                autoplay:true,
                autopause: true,
				interval: 6500,
                api: true
            });

            $("a","#cScrollTrack ul li").mouseover(function(){
                scroll.pause();
            }).click(function(){
                scroll.seekTo($(this).attr('rel'));
            })
        }
    },
	
    /*****************************************************************
	* DEPENDENCY: jQuery, jQueryTools
    * Ajax methods to add the user to the mailing list
    *****************************************************************/	
	newsletter: {
		init: function(){
			$('#btn-subscribe').click(function(e){
				$.ajax({
					url: dlga.docRoot+'signup.php5',
					type: 'POST',
					data: ({ email: $('#email').val() }),
					success: function(data){
						var modalTarget = $(e.target).attr('rel');
						$(modalTarget).css({'width':'500px'}).find('#append-msg').empty().append(data);
						$(this).overlay({ fixed:false,target:modalTarget,mask:{color:'#000',loadSpeed:150,opacity:0.8},load:true})
					}
				})
			})
		}
	},
	
	
	
	/*****************************************************************
	* DEPENDENCY: jQuery, jQueryTools
    * Programs scroller for sidebar
    *****************************************************************/	
	
	smoothPageScroll: {
        init: function(expose_target){ // expose_target is a boolean: turns exposing off or on
            //smooth page scrolling to internal targets
            $(function(){
                $('a[href*=#]').click(function(){
                if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
                    && location.hostname == this.hostname) {
                        var $target = $(this.hash);
                        if(expose_target){ $target.expose({color:'#000',loadSpeed:0,opacity:0.65}) }
                        $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
                        if ($target.length) {
                            var targetOffset = $target.offset().top;
                            $('html,body').animate({scrollTop: targetOffset-10}, 500);
                            return false;
                        }
                    }
                });
            })
        }
    }
	
	
	
	
	
}




// functions that should always be executed in the header
$(document).ready(function(){ dlga.nav_menu.init(); })
