var addSwitcher = function(oThis) {
    var sSel = 'div.frame';
    var iSpeed = 500;
    var iTimeout = 2000;
    
    if (!$(oThis).hasClass('referenzen')) iTimeout = 5000;
    
    if ($(oThis).hasClass('referenzen')) sSel = 'a.logo';
    var iNum = $(oThis).find(sSel).length;
    
    var showNum = function(iCurr) {
        if ($(oThis).hasClass('tabbox') && (iNum > 1)) {
            $(oThis).find('h3 span').remove();
            $(oThis).children('h3').append('<span> - ' + iCurr + ' von ' + iNum + '</span>');
        }
    };
    var nextElem = function() {
        var iCurr = $(oThis).find(sSel + ':visible').prevAll(sSel).length + 1;
        
        if (iCurr >= iNum) iCurr = 0;
        $(oThis).find(sSel + ':visible').fadeOut(iSpeed);
        $(oThis).find(sSel + ':eq('+iCurr+')').fadeIn(iSpeed);
        
        showNum(iCurr + 1);
        
        return false;
    };
    var prevElem = function() {
        var iCurr = $(oThis).find(sSel + ':visible').prevAll(sSel).length - 1;
        
        if (iCurr < 0) iCurr = iNum - 1;
        $(oThis).find(sSel + ':visible').fadeOut(iSpeed);
        $(oThis).find(sSel + ':eq('+iCurr+')').fadeIn(iSpeed);
        
        showNum(iCurr + 1);
        
        return false;
    };
    var doTimeout = function() {
        if ($(oThis).children('a.prev').css('display') == 'none') {
            nextElem();                
        }
        
        if ($(oThis).children(':visible').length) window.setTimeout(doTimeout, iTimeout);
    };
    
    $(oThis).find(sSel).not(':first').css('display', 'none');
    
    if (iNum > 1) window.setTimeout(doTimeout, iTimeout);
    
    $(oThis).children('a.prev').click(function() { this.blur(); return prevElem(); });
    $(oThis).children('a.next').click(function() { this.blur(); return nextElem(); });
    
    //$(oThis).find('a.prev, a.next').css('top', parseInt($(oThis).innerHeight() / 2 - 8) + 'px');
    showNum(1);
    
    if (($(oThis).find('a.prev').css('display') == 'none') && (iNum > 1)) {
        $(oThis).mouseover(function() { $(oThis).find('a.prev, a.next').css('display', 'inline'); })
                .mouseout(function()  { $(oThis).find('a.prev, a.next').css('display', 'none'  ); });
    }
    
    if (iNum == 1) $(oThis).find('a.prev, a.next').css('display', 'none');
}

$(document).ready(function() {
    //alert(document.getElementById('flashsource').innerHTML);
    //alert($('#flashsource').html());
    //$(document).ready(function() {
   	    //alert($('span#flashsource').html());
        //var so = new SWFObject($('span#flashsource a').attr('href'), "DCI", "527", "137", "6", "#ffffff");
		   	//so.write("flashcontent");
		//});
		
		sSrc = $('span#flashsource a').attr('href').length ? $('span#flashsource a').attr('href') : $('span#flashsource').text();
		
		var so = new SWFObject(sSrc, "DCI", "527", "137", "6", "#ffffff");
		so.write("flashcontent");
		
		$('div#screen_start div#startbox_news').each(function() { addSwitcher(this); });
		$('div#screen_start div#startbox_footer_frame div.referenzen_c div.referenzen').each(function() { addSwitcher(this); });
		
		
    $('input[type=image]').unbind('mouseover').mouseover(function() {
        if (($(this).attr('src').indexOf('button_') != -1) || ($(this).attr('src').indexOf('arrow.png') != -1)) {
            $(this).attr('src', $(this).attr('src').substr(0, $(this).attr('src').length - 4) + '_active.png');
        }
    }).unbind('mouseout').mouseout(function() {
        if ((($(this).attr('src').indexOf('button_') != -1) || ($(this).attr('src').indexOf('arrow_active.png') != -1)) && ($(this).attr('src').indexOf('_active') != -1)) {
            $(this).attr('src', $(this).attr('src').substr(0, $(this).attr('src').length - 11) + '.png');
        }
    });
    
    $('input.inlineLabel').each(function() {
  	    jQuery.data(this, 'inlineLabel', $(this).attr('value'));
  	    
  	    $(this).focus(function() { if ($(this).attr('value') == jQuery.data(this, 'inlineLabel')) this.value = ''; })
  	            .blur(function() { 
  	                //alert(this.defaultValue);
  	                //var xy = $(this);
  	                if ($(this).attr('value') == '') this.value = jQuery.data(this, 'inlineLabel');
  	           });
  	});
});