/**
 * Image Replace
 * Appends some spans to selection, so with css nice IR can happen)
 * @author AK|Peppered
 */

jQuery.fn.ImageReplace = function(options) {
	var defaults = {
		hover: false
	};
	options = $.extend(defaults, options);
	if (document.styleSheets[0].disabled) return false;
	if (this.length < 1) return false;
	
	if (this.get(0).nodeName.toLowerCase() == 'body') {
		// old style replace via classnames
		$('.IR, .IR-anchors a').append('<span class="IR-aid"></span>');	// single element IR & descendant anchors of an element
		$('.IR.IR-hover span.IR-aid, .IR-anchors.IR-anchors-hover a span.IR-aid').append('<span></span>');	// append another span when it has a hover state
		$('.IR, .IR-anchors').addClass('IRActive');		
	}
	else {
		this.each(function() {
			//$.log(this);
			$(this).addClass('ir');		
			$(this).append('<span class="ir-aid"></span>');	
			if (options.hover == true) {
				$(this).children('span.ir-aid').addClass('ir-aid-hover');
				$(this).children('span.ir-aid').append('<span></span>');
			}
	
			$(this).addClass('irActive');
		});		
	}
}

/**
 * preload images
 */

aImgsPreload = new Array(); // gets filled throughout different .incs
aImgsPreload.push('tab_sponsors.gif','tab_fotos.gif');
for (i = 0; i < aImgsPreload.length; i++) {
	$("<img>").attr("src", '/images/' + aImgsPreload[i]);
}


//dimScreen()
//by Brandon Goldman
jQuery.extend({
    //dims the screen
    dimScreen: function(speed, opacity, callback) {
        if(jQuery('#__dimScreen').size() > 0) return;
        
        if(typeof speed == 'function') {
            callback = speed;
            speed = null;
        }

        if(typeof opacity == 'function') {
            callback = opacity;
            opacity = null;
        }

        if(speed < 1) {
            var placeholder = opacity;
            opacity = speed;
            speed = placeholder;
        }
        
        if(opacity >= 1) {
            var placeholder = speed;
            speed = opacity;
            opacity = placeholder;
        }

        speed = (speed > 0) ? speed : 500;
        opacity = (opacity > 0) ? opacity : 0.5;
        return jQuery('<div></div>').attr({
                id: '__dimScreen'
                ,fade_opacity: opacity
                ,speed: speed
            }).css({
            background: '#000'
            ,height: $(document).attr('height') + 'px'
            ,left: '0px'
            ,opacity: 0
            ,position: 'absolute'
            ,top: '0px'
            ,width: $(document).attr('width') + 'px'
            ,zIndex: 999
        }).appendTo(document.body).fadeTo(speed, opacity, callback);
    },
    
    //stops current dimming of the screen
    dimScreenStop: function(callback) {
        var x = jQuery('#__dimScreen');
        var opacity = x.attr('fade_opacity');
        var speed = x.attr('speed');
        x.fadeOut(speed, function() {
            x.remove();
            if(typeof callback == 'function') callback();
        });
    }
});