/* IE6nomore
------------------------------------------------------------------------------------------------ */

$.IE6nomore = function() {

    if(!$('#ie6nomore').length)
        return;

    $('#ie6nomore').css({
        'left'      : 0,
        'top'       : 0,
        'bottom'    : 0,
        'right'     : 0,
        'position'  : 'absolute',
        'z-index'   : 9999
    });

};

/* Swap image
------------------------------------------------------------------------------------------------ */

function swapImage(element, newimage) {

    var oldsrc      = element.src;
    element.src     = newimage;

    if (!element.onmouseout) {
        element.onmouseout = function() {
            swapImage(this, oldsrc);
        }
    }

}

/* Spam protection
------------------------------------------------------------------------------------------------ */

function getAdr(prefix, postfix, text) {
    document.write('<a href="mailto:' + prefix + '@' + postfix + '">' + (text ? text.replace(/&quot;/g, '"').replace(/%EMAIL%/, prefix + '@' + postfix) : prefix + '@' + postfix) + '</a>');
}

/* Get url vars
------------------------------------------------------------------------------------------------ */

$.getUrlVars = function() {

    var vars    = [],
        hash    = '',
        hashes  = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');

    $(hashes).each(function() {
        hash = this.split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    });

    return vars;
};


/*------------- Diashow ------------ */

function diashow() {
	  var $old = $('#imagestack IMG.oben');
	
	  if($old.next().length) {
		var $new = $old.next();
	  } else {
		var $new = $('#imagestack IMG:first');
	  }
	  
	  $old.addClass('mitte');
	  $old.removeClass('oben');
	  $new.css({opacity: 0.0});
	  $new.addClass('oben');
	
	  $new.animate({opacity: 1.0}, 2000, function() {
		$old.removeClass('mitte');
	  });
}

	
/*------------- Zufallszahl für Seitenbilder ------------ */
function randomPageImage(n, path) {
	 a = 1 + (n-1) * (Math.random());
	 a = Math.round(a);
	 
	 //alert("Path: " + path + "; a: " + a);
	 
	 image = "url(" + path + "image_page" + a + ".png)";
	 
	 //alert("Bild: " + image);
	 
	 $("#page").css("background", image);
	 
}

/* DOM
------------------------------------------------------------------------------------------------ */

$(document).ready(function() {

    // IE6nomore

    $.IE6nomore();
    
    // Forms

    $('#contact').forms({
        'confirmpage'   : 'iframe'
    });

    $('#event').forms({
        'confirmpage'   : 'iframe'
    });

    $('textarea').autogrow();


    // Onlinetools object

    $('.onlinetool .popup').popup();
	
    // Menu
    
    $('#nav').menu();
	
	//Pageswitch
	$('#team_overview', '.gesellschafter').pageswitch(1);
	$('#team_overview', '.berufstraeger').pageswitch(2);
	$('#team_overview', '.angestellte').pageswitch(2);
	$('#team_overview', '.freiemitarbeiter').pageswitch(2);
	
});

