function nav_hover_in(nav_id, hover_enable) {
	if(hover_enable == true) { document.getElementById('nav_item_strich_'+nav_id).style.backgroundImage = 'url('+base_dir+'images/index/nav_strich.png)'; }
}

function nav_hover_out(nav_id, hover_enable) {
	if(hover_enable == true) { document.getElementById('nav_item_strich_'+nav_id).style.backgroundImage = 'url('+base_dir+'images/blank.gif)'; }
}

function sponsor_toggle_src(spo_id, img_src) {
	var i = 0;
	while(document.getElementsByName('sponsor_' + spo_id)[i] != null) {
		document.getElementsByName('sponsor_' + spo_id)[i].src = img_src;
		i++;
	}
}

function toggle_sub_nav(parent_id) {
	var toggle_dir;
	
	for(var i = 1; document.getElementById("parent_item_" + parent_id + "_" + i) != null; i++) {
		if(document.getElementById("parent_item_" + parent_id + "_" + i).style.display == "") {
			document.getElementById("parent_item_" + parent_id + "_" + i).style.display = "none";
			toggle_dir = "out";
		} else {
			document.getElementById("parent_item_" + parent_id + "_" + i).style.display = "";
			toggle_dir = "in";
		}
	}
	
	if(toggle_dir == "out") { makeAJAXRequest(base_dir + "nav/remove_open/" + parent_id + "/"); }
	if(toggle_dir == "in") { makeAJAXRequest(base_dir + "nav/set_open/" + parent_id + "/"); }
}

function toggle_item(item_name) {
	if(document.getElementById(item_name) != null) {
		if(document.getElementById(item_name).style.display == "") {
			document.getElementById(item_name).style.display = "none";
		} else {
			document.getElementById(item_name).style.display = "";
		}
	}
}

var fenster;

function popupimage(url, ww, hh) {
	if(fenster) { fenster.close(); }
	ww = ww + 20;
	hh = hh + 20;
	var parameter = popup_center(ww, hh);
	fenster = window.open('', '', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizeable=no,width='+ww+',height='+hh+parameter);
	fenster.document.open();
	fenster.document.write("<html><head></head><body bgcolor=\"#DBDBDB\"><center><img src=\""+url+"\" alt=\"\"></center></body></html>");
	fenster.document.close();
	fenster.focus();
}

function popupurl(url, ww, hh) {
	if(fenster) { fenster.close(); }
	var parameter = popup_center(ww, hh);
	fenster = window.open(url, '', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizeable=no,width='+ww+',height='+hh+parameter);
	fenster.focus();
}

function popupurlscroll(url, ww, hh) {
	if(fenster) { fenster.close(); }
	var parameter = popup_center(ww, hh);
	fenster = window.open(url, '', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizeable=no,width='+ww+',height='+hh+parameter);
	fenster.focus();
}

function popup(module, content, ww, hh) {
	if(fenster) { fenster.close(); }
	ww = ww + 10;
	hh = hh + 10;
	var parameter = popup_center(ww, hh);
	fenster = window.open(base_dir + 'popup/' + module + '/' + content, '', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizeable=no,width='+ww+',height='+hh+parameter);
	fenster.focus();
}

function popup_center(ww, hh) {
	var parameter;
	if(ww < screen.availWidth || hh < screen.availHeight) {
		x = (screen.availWidth - ww - 12) / 2;
		y = (screen.availHeight - hh - 104) / 2;
		if(window.opera) { y = 0; } // Opera positioniert unter den Symbolleisten
		if(x < 0 || y < 0) { x = 0; y = 0; }
		parameter = ",left=" + Math.round(x) + ",top=" + Math.round(y);
	}
	return parameter;
}

function fensterschliessen() {
	if(fenster) { fenster.close(); }
}


function SpoFader() {
	this.name;
	this.images;
	this.urls;
	this.text_1;
	this.text_2;
	this.text_3;
	this.max_image;
	this.display_time;
	this.interval;
	this.opacity = 1;
	this.increase = 1;
	this.decrease = 0;
	this.i = 0;
	this.next_i = 1;
	this.target;
	this.load_next_image = new Image();
	
	this.SpoInitFader = function() {
		this.interval = setInterval(this.name + ".SpoStartFading()", (this.display_time * 1000));
		this.load_next_image.src = this.images[this.next_i];
	}

	this.SpoStartFading = function() {
		clearInterval(this.interval);
		this.interval = setInterval(this.name + ".SpoFade()", 10);
	}

	this.SpoFade = function() {
		if(this.opacity < 1 && this.increase) {
			this.opacity += 0.03;
		} else {
			this.increase = 0;
			this.decrease = 1;
		}
		
		if(this.opacity > 0 && this.decrease) {
			this.opacity -= 0.03;
		} else {
			this.increase = 1;
			this.decrease = 0;
		}
		
		document.getElementById(this.name).style.filter = "alpha(opacity=" + (this.opacity * 100) + ")";
		document.getElementById(this.name).style.opacity = this.opacity;
		
		if(this.opacity > 0.99) {
			clearInterval(this.interval);
			this.interval = setInterval(this.name + ".SpoStartFading()", (this.display_time * 1000));
		}
		
		if(this.opacity < 0) {
			this.i++;
			this.next_i = (this.i + 1);
			if(this.i > this.max_image) { this.i = 0; }
			if(this.next_i > this.max_image) { this.next_i = 0; }
			
			if(this.urls[this.i] == "javascript:void(0);") {
				this.target = "_self";
			} else {
				this.target = "_blank";
			}
			
			document.getElementById(this.name).src = this.images[this.i];
			this.load_next_image.src = this.images[this.next_i];
			
			if(document.getElementById(this.name + "_url_1") != null) {
				document.getElementById(this.name + "_url_1").href = this.urls[this.i];
				document.getElementById(this.name + "_url_1").target = this.target;
			}
			if(document.getElementById(this.name + "_url_2") != null) {
				document.getElementById(this.name + "_url_2").href = this.urls[this.i];
				document.getElementById(this.name + "_url_2").target = this.target;
			}
			if(document.getElementById(this.name + "_text_1") != null) {
				document.getElementById(this.name + "_text_1").innerHTML = this.text_1[this.i];
			}
			if(document.getElementById(this.name + "_text_2") != null) {
				document.getElementById(this.name + "_text_2").innerHTML = this.text_2[this.i];
			}
			if(document.getElementById(this.name + "_text_3") != null) {
				document.getElementById(this.name + "_text_3").innerHTML = this.text_3[this.i];
			}
			
			this.opacity = 0.01;
			this.increase = 1;
			this.decrease = 0;
		}
	}
}


function toggle_div_fade(fade_name, speed) {
	var no_fading = false;
	var name;
	if(speed == null) { speed = 6; }
	
	fade_divs = new Array('download_upload', 'image_upload', 'static_link');
	
	for (var i = 0; i < fade_divs.length; i++) {
		name = fade_divs[i];
		if(name != fade_name) {
			if(document.getElementById(name + '_frame_div') != null) {
				if(document.getElementById(name + '_frame_div').style.display == '') {
					fade_toggle_div(name + '_frame_div', speed, '', 'toggle_div_fade("' + fade_name + '", ' + speed + ')');
					no_fading = true;
				}
			}
		}
	}
	
	if(no_fading == false) {
		fade_toggle_div(fade_name + '_frame_div', speed, 'resize_frame("' + fade_name + '_iframe")');
	}
}

function resize_frame(frame_name) {
	var framefenster = document.getElementById(frame_name);
	if(framefenster != null) {
		if(framefenster.contentWindow.document.body) {
			var framefenster_size = framefenster.contentWindow.document.body.offsetHeight;
			if(document.all && !window.opera) {
				framefenster_size = framefenster.contentWindow.document.body.scrollHeight;
			}
		framefenster.style.height = framefenster_size + 'px';
		}
	}
}


// Div Fade-In/Fade-Out Funktionen

var fading_div;
var fade_in_function = false;
var fade_out_function = false;
var fade_speed = 6;
var div_opacity;

function fade_toggle_div(div_name, speed, fade_in_func, fade_out_func) {
	clearInterval(fading_div);
	
	if(typeof speed != "undefined" && speed != '') { fade_speed = speed; }
	if(document.getElementById(div_name).style.display == '') {
		div_opacity = 1;
		if(typeof fade_out_func != "undefined" && fade_out_func != '') { fade_out_function = fade_out_func; }
		fading_div = setInterval("fade_div(false, '" + div_name + "')", 10);
	} else {
		div_opacity = 0;
		if(typeof fade_in_func != "undefined" && fade_in_func != '') { fade_in_function = fade_in_func; }
		fading_div = setInterval("fade_div(true, '" + div_name + "')", 10);
	}
}

function fade_div(increase, div_name) {
	if(div_opacity == 0 && increase) {
		document.getElementById(div_name).style.display = '';
	}
	
	if(div_opacity > 0 && !increase) {
		div_opacity -= fade_speed / 100;
	}
	
	if(div_opacity < 1 && increase) {
		div_opacity += fade_speed / 100;
	}
	
	document.getElementById(div_name).style.filter = "alpha(opacity=" + (div_opacity * 100) + ")";
	document.getElementById(div_name).style.opacity = div_opacity;
	
	if(div_opacity < 0) {
		div_opacity = 0;
		clearInterval(fading_div);
		document.getElementById(div_name).style.display = 'none';
		
		if(fade_out_function) {
			setTimeout(fade_out_function, 1);
			fade_out_function = false;
		}
	}
	
	if(div_opacity > 0.99 && increase) {
		div_opacity = 1;
		clearInterval(fading_div);
		
		if(fade_in_function) {
			setTimeout(fade_in_function, 1);
			fade_in_function = false;
		}
	}
}


var image_loaded = false;
var load_img;
var load_waiting;
var load_fading = false;
var load_decrease = true;
var load_opacity = 1;
images_loaded = new Array();

function toggle_view_image_full(image_src, width, height) {
	if(typeof width != "undefined" && width != '') {
		document.getElementById('view_image_full').style.width = width + 'px'; 
		document.getElementById('view_image_full').style.marginLeft = '-' + Math.round(width / 2) + 'px'
	}
	if(typeof height != "undefined" && height != '') {
		document.getElementById('view_image_full').style.height = height + 'px';
		document.getElementById('view_image_full').style.marginTop = '-' + Math.round(height / 2) + 'px'
	}
	
	if(images_loaded[image_src]) {
		document.getElementById('full_image').src = image_src;
		image_loaded = true;
	} else {
		document.getElementById('full_image').src = base_dir + "images/loading_circle.gif";
		image_loaded = false;
		load_decrease = true;
	}
	fade_toggle_div('view_image_full', 4, 'start_loading_image(\'' + image_src + '\', ' + width + ', ' + height + ')');
	images_loaded[image_src] = true;
}

function start_loading_image(image_src, width, height) {
	if(image_src != '' && width != '' && height != '') {
		if(!image_loaded) {
			load_img = new Image(width, height);
			load_img.src = image_src;
			load_waiting = setInterval("load_image()", 10);
		}
	}
}

function load_image() {
	if(load_img.complete == true && load_fading == false) {
		image_loaded = true;
		load_fading = true;
	}
	
	if(load_fading == true) {
		if(load_opacity > 0 && load_decrease) {
			load_opacity -= 0.03;
		}
		
		if(load_opacity < 1 && !load_decrease) {
			load_opacity += 0.03;
		}
		
		document.getElementById('full_image').style.filter = "alpha(opacity=" + (load_opacity * 100) + ")";
		document.getElementById('full_image').style.opacity = load_opacity;
		
		if(load_opacity < 0) {
			load_decrease = false;
			document.getElementById('full_image').src = load_img.src;
		}
		
		if(load_opacity > 0.99 && !load_decrease) {
			clearInterval(load_waiting);
		}
	}
}

function makeAJAXRequest(url, return_function, error_function, send_data) {
	try{
		// Opera 8.0+, Firefox, Safari
		httpRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				if(typeof(window[error_function]) == "function") {
					window[error_function]();
				}
				return false;
			}
		}
	}
	
	httpRequest.onreadystatechange = function() {
		if(httpRequest.readyState == 4) {
			if(typeof(window[return_function]) == "function") {
				window[return_function](httpRequest.responseText);
			}
			httpRequest.abort();
		}
	}
	
	if(send_data != null) {
		httpRequest.open('POST', url, true);
		httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		httpRequest.send(send_data);
	} else {	
		httpRequest.open('GET', url, true);
		httpRequest.send(null);
	}
	
}

function detectFlash() {
	var flash = false;
	var max_version = 10;
	
	if(typeof(navigator.plugins["Shockwave Flash"]) == "object") { flash = true; }
	else if(typeof(ActiveXObject) == "function") {
		for(var i = 2; i < (max_version + 1); i ++) {
            		try {
				if(typeof(new ActiveXObject("ShockwaveFlash.ShockwaveFlash." + i)) == "object") { flash = true; }
			}
			catch(error) { }
		}
	}
	
	return flash;
}

function string_create_urls(input) {
    return input
    .replace(/(ftp|http|https|file):\/\/[\S]+(\b|$)/gim, '<a href="$&" target="_blank">$&</a>')
    .replace(/([^\/])(www[\S]+(\b|$))/gim, '$1<a href="http://$2" target="_blank">$2</a>');
} 

var mouse_x;
var mouse_y;

function save_position(event) {
	mouse_x = event.pageX;
	mouse_y = event.pageY;
}

document.onmousedown = save_position;

