/*
 * Avoid conflicts with other libraries such as Prototype
 * Use _$ instead of $
 * If use $ the prototype library is used instead
*/
jQuery.noConflict();
window.jQuery = window._$ = jQuery;

/*
 * Begin jQuery stuff
 *
*/
(function(_$){
	// jQuery delayed event execution.
    _$.fn.delay = function(options) {
        var timer;
        var delayImpl = function(eventObj) {
            if (timer != null) {
                clearTimeout(timer);
            }
            var newFn = function() {
                options.fn(eventObj);
            };
            timer = setTimeout(newFn, options.delay);
        }
       
        return this.each(function() {
            var obj = _$(this);
            obj.bind(options.event, function(eventObj) {
                 delayImpl(eventObj);  
            });
        });
    };
})(jQuery);

/**
* Fullscreenr - lightweight full screen background jquery plugin
* By Jan Schneiders
* Version 1.0
* www.nanotux.com
**/
(function(_$){	
	_$.fn.fullscreenr = function(options) {
		if(options.height === undefined) alert('Please supply the background image height, default values will now be used. These may be very inaccurate.');
		if(options.width === undefined) alert('Please supply the background image width, default values will now be used. These may be very inaccurate.');
		if(options.bgID === undefined) alert('Please supply the background image ID, default #bgimg will now be used.');
		var defaults = { width: 1280,  height: 1024, bgID: 'bgimg' };
		var options = _$.extend({}, defaults, options); 
		_$(document).ready(function() { _$(options.bgID).fullscreenrResizer(options);	});
		_$(window).bind("resize", function() { _$(options.bgID).fullscreenrResizer(options); });		
		return this; 		
	};	
	_$.fn.fullscreenrResizer = function(options) {
		// Set bg size
		var ratio = options.height / options.width;	
		// Get browser window size
		var browserwidth = _$(window).width();
		var browserheight = _$(window).height();
		// Scale the image
		if ((browserheight/browserwidth) > ratio){
		    _$(this).height(browserheight);
		    _$(this).width(browserheight / ratio);
		} else {
		    _$(this).width(browserwidth);
		    _$(this).height(browserwidth * ratio);
		}
		// Center the image
		_$(this).css('left', (browserwidth - _$(this).width())/2);
		_$(this).css('top', (browserheight - _$(this).height())/2);
		return this; 		
	};
})(jQuery);
