var hotEntry = null;
var proImages = [];
var proIndex = 0;

var preloadImageList = [
	'ap_left.gif','ap_right.gif','babg.png','back.gif','bu_abs.gif','bu_auf.gif',
	'bu_aufs.gif','bu_zu.gif','cb_a.gif','cb_c.gif','cb_h.gif','checkbox.png',
	'close.png','close_warn.png','empty.png','fbg.png','fbg_err.png','home.gif',
	'home_h.gif','icon.png','logo.png','pf_auf.gif','pf_back_c.gif','pf_back_h.gif',
	'pf_next_c.gif','pf_next_h.gif','pf_zu_c.gif','pf_zu_h.gif','plan.png',
	'safari-checkbox.png','sb_sav.gif','schbg.gif','screenshot.png','top.gif',
	'tpix.gif','trans.gif','wko.gif','wko.jpg'
];

$(function(){
	// Brute force preload.
	for( var i=0; i<preloadImageList.length; i++ ){ new Image().src = "../images/" + preloadImageList[i]; }


	for( var i=0; i<proImages.length; i++ ){ new Image().src = proImages[i]; }
	hotEntry = $( ".promen_title_open" )[0];
	$( ".promen_title_open,.promen_title_close" ).mouseover(function(e){
		if( this.className == "promen_title_close" ){
			this.style.backgroundImage = "url(images/pf_zu_h.gif)";
			this.style.color = "#7b1956";
		}else{
			// Sind wir ohnehin heiss und können bleiben wie wir sind.
			//this.style.backgroundImage = "";
			//this.style.color = "";
		}
	});
	$( ".promen_title_open,.promen_title_close" ).disableSelection();
	$( ".promen_title_open,.promen_title_close" ).mouseout(function(e){
		if( this.className == "promen_title_close" ){
			this.style.backgroundImage = "url(images/pf_zu_c.gif)";
			this.style.color = "#868485";
		}else{
			// Sind wir ohnehin heiss und können bleiben wie wir sind.
			//this.style.backgroundImage = "";
			//this.style.color = "";
		}
	});

	$( ".promen_title_open,.promen_title_close" ).click(function(e){
		if( hotEntry && hotEntry != this ){
			$( "#content_" + hotEntry.id ).hide( 'blind' );
			hotEntry.className = "promen_title_close";
			$( hotEntry ).css({
				backgroundImage 	: "url(images/pf_zu_c.gif)",
				color				: "#868485"
			});
		}
		if( hotEntry != this ){
			$( "#content_" + this.id ).show( 'blind' );
			this.className = "promen_title_open";
		}
		hotEntry = this;
		$( hotEntry ).css({
			backgroundImage 		: "url(images/pf_auf.gif)",
			color					: "#7b1956"
		});
	});

	$( "input", $(".nl_feld") ).focus(function(e){
		if( !this.cleared ){
			this.cleared = true;
			this.value = "";
		}
	});
	$( "input", $(".nl_feld") ).click(function(e){
		if( !this.cleared ){
			this.cleared = true;
			this.value = "";
		}
	});


	$(".nl_group").mouseover(function(){
		if( !this.checked ){ $(this).css({'background-image' : 'url(images/cb_h.gif)'}); }
	}).mouseout(function(){
		if( !this.checked ){ $(this).css({'background-image' : 'url(images/cb_c.gif)'}); }
	}).click(function(){
		this.checked = this.checked ? false : true;
		$(this).css({'background-image' : this.checked ? 'url(images/cb_a.gif)' : 'url(images/cb_h.gif)' });
		$( "input[name=" + this.id + "]" ).val( this.checked ? "on" : "" );
	});
	$(".nl_group").disableSelection();
});

function nextImage(){
	proIndex++;
	if( proIndex >= proImages.length ){ proIndex = 0; }
	showImage();
}
function prevImage(){
	proIndex--;
	if( proIndex < 0 ){ proIndex = proImages.length - 1; }
	showImage();
}
function showImage(){
	$( "#pro_image" )[0].src = proImages[proIndex];
	$( "#image_ctr" ).html( (proIndex+1) );
}

