var g_current = 1; 
var g_last = 0;
var g_switch = 0;


(function($) { 
    $.fn.innerfade = function(options) { 
        return this.each(function() {   
            $.innerfade(this, options); 
        }); 
    }; 

    $.innerfade = function(container, options) { 
        var settings = { 
            'speed':            'normal', 
            'timeout':          10000, 
            'containerheight':  'auto', 
            'runningclass':     'innerfade', 
            'children':         null 
        }; 
        if (options) 
            $.extend(settings, options); 
        if (settings.children === null) 
            var elements = $(container).children(); 
        else 
            var elements = $(container).children(settings.children); 
        if (elements.length > 1) { 
            $(container).css('position', 'relative').css('height', settings.containerheight).addClass(settings.runningclass); 
            for (var i = 0; i < elements.length; i++) { 
                $(elements[i]).css('z-index', String(elements.length-i)).css('position', 'absolute').hide(); 
            }; 
            
			this.ifchanger = setTimeout(function() { 
                $.innerfade.next(elements, settings, 1, 0); 
            }, settings.timeout); 
            $(elements[0]).show(); 
        } 
    }; 

    $.innerfade.next = function(elements, settings, current, last) {
		if(g_switch == 0){
			g_current = current;
			g_last = last;
		}
		else
		{
			current = g_current;
			last = g_last;
			g_switch = 0;
		}
		
        $(elements[last]).fadeOut(settings.speed); 
        $(elements[current]).fadeIn(settings.speed, function() { 
            removeFilter($(this)[0]); 
        }); 
        
        if ((current + 1) < elements.length) { 
            current = current + 1; 
            last = current - 1; 
        } else { 
            current = 0; 
            last = elements.length - 1; 
        } 
		
		for(i=1;i<5;i++) { 
            $('#img0'+i+'feature').css("background-image", "url(fileadmin/templates/images/slider/white.png)"); 
        } 
        $('#img0'+(g_current + 1)+'feature').css("background-image", "url(fileadmin/templates/images/slider/blue.png)");
		 
		
		
        this.ifchanger = setTimeout((function() { 
            $.innerfade.next(elements, settings, current, last); 
        }), settings.timeout); 
    }; 
})(jQuery); 

// **** remove Opacity-Filter in ie **** 
function removeFilter(element) { 
    if(element.style.removeAttribute){ 
        element.style.removeAttribute('filter'); 
    } 
} 

$(document).ready(function() { 

	for(i=1;i<5;i++) { 
            $('#img0'+i+'feature').css("background-image", "url(fileadmin/templates/images/slider/white.png)"); 
        } 
        $('#img0'+(g_current)+'feature').css("background-image", "url(fileadmin/templates/images/slider/blue.png)");

    $('ul#image_rotate').innerfade({ 
        speed: 1000, 
        timeout: 10000, 
        containerheight: '323px' 
    }); 
        
    $('#promonav .links').children('li').children('a').click(function() { 
        for(i=1;i<5;i++) { 
            $('#the'+i+'feature').css("display", "none");
			$('#img0'+i+'feature').css("background-image", "url(fileadmin/templates/images/slider/white.png)"); 
        } 

        $('#the'+(jQuery(this).attr('rel'))+'feature').css("display", "block");
		$('#img0'+($(this).attr('rel'))+'feature').css("background-image", "url(fileadmin/templates/images/slider/blue.png)");
		g_current = parseInt($(this).attr('rel') - 1);
		g_last = parseInt($(this).attr('rel') - 2);
		if(g_last < 0)
			g_last = 3;
		g_switch = 1;
 		

    }); 

}); 
