




function changeHeaderBanner(i)
{
//$('product_box').fade();
//$('product_box').appear();

 document.getElementById("product_box").style.backgroundImage = "url(images/header"+i+".png)";

 if(i<5){
    i++;
 }
 else{
    i=1;
 }


 setTimeout("changeHeaderBanner("+i+")", 5000)

   

}





function isArray(obj) {
	if (obj.constructor.toString().indexOf("Array") == -1)
		return false;
	else
		return true;
}

function printOptions (array)
{
	var retval = "";
	
	for (var i = 0; i < array.length; i++){ 
		retval += "<option>" + array[i] + "</option>\n"; 
	} 
	
	return retval;
}


function openAGB() {
	window.open("content/support_agb.php", "_blank", "width=600,height=400,status=no,scrollbars=yes,resizable=yes");
	return false;
}

var last_slide_for_home = 1;
var newId = 2;

function slideHome()
{
	$("#home_slider_content").height($("#home_slider").height());
	
	var last = $("#home_slider").children("#home_slider_" + last_slide_for_home);
	var cur = $("#home_slider").children("#home_slider_" + newId);
	var last_img = $("#home_slider_image_" + last_slide_for_home);
	var cur_img = $("#home_slider_image_" + newId);
	
	last.css({
		"border" : "0px solid #ff9900",
		"border-right" : "0px solid #ffffff",
		"font-weight" : "normal",
		"padding" : "3px",
		"background" : "#ffffff"
	});
	last_img.hide();
	cur_img.show();
	cur.css({
		"border" : "0px solid #ff9900",
		"border-right" : "0px solid #ff9900",
		"font-weight" : "normal",
		"padding" : "3px",
		"background" : "#ff9900"
	});
	
//	$("#home_slider_content").html(cur.children(".content_home_slider_img").html());
	
	last_slide_for_home = newId;
	if (newId == 5)
		newId = 1;
	else
		newId++;
}

function correctPNG() // correctly handle PNG transparency in Win IE 5.5 or higher.
{
	for(var i=0; i<document.images.length; i++)
   {
	  var img = document.images[i]
	  var imgName = img.src.toUpperCase()
	  if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
	     {
		 var imgID = (img.id) ? "id='" + img.id + "' " : ""
		 var imgClass = (img.className) ? "class='" + img.className + "' " : ""
		 var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
		 var imgStyle = "display:inline-block;" + img.style.cssText 
		 if (img.align == "left") imgStyle = "float:left;" + imgStyle
		 if (img.align == "right") imgStyle = "float:right;" + imgStyle
		 if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle		
		 var strNewHTML = "<span " + imgID + imgClass + imgTitle
		 + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
	     + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
		 + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
		 img.outerHTML = strNewHTML
		 i = i-1
	     }
   }
}



$(document).ready(function() {

	var browser = navigator.userAgent.toLowerCase();
	var ganzzahl = parseInt(navigator.appVersion);
	var explorer6 = (browser.indexOf("msie 6.0") !=-1);
	
	if (explorer6)
	{
		var text = "";
		$("div").each(function () {
			var bg_img = $(this).css("background-image");
			if (bg_img!=undefined && bg_img!="none")
			{
				var img = bg_img.substr(5,bg_img.length-7);
				$(this).css({
					"background" : "none",
					"filter" : "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+img+"', sizingMethod='scale');"
				});
				text += bg_img.substr(5,bg_img.length-7)+"\n";
			}
		});
		correctPNG();
	}
	
	if ($("#home_slider").length>0)
	{
		$("#home_slider_content").height($("#home_slider").height()-1);
		myInterval = setInterval("slideHome()",3000);
	}
	
	
	$(".navi").children("a").mouseover(function () {
		if (!$(this).hasClass("akt")) {
			$(this).children(".left").addClass("left_akt");
			$(this).children(".right").addClass("right_akt");
			$(this).children(".item").addClass("item_akt");
			
			var alt = $(this).children(".item").children("img").attr("alt");
			$(this).children(".item").children("img").attr("src", "images/navi_" + alt + "_akt.png");
		}
	});

	
	$(".navi").children("a").mouseout(function () {
		if (!$(this).hasClass("akt")) {
			$(this).children(".left").removeClass("left_akt");
			$(this).children(".right").removeClass("right_akt");
			$(this).children(".item").removeClass("item_akt");

			var alt = $(this).children(".item").children("img").attr("alt");
			$(this).children(".item").children("img").attr("src", "images/navi_" + alt + ".png");
		}
	});
	
	$("#back_link_home").hide();
	$(".news_big").hide();
	$("#news_overview span").click(function () {
		$("#back_link_home").slideDown();
		$("#home_content").slideUp();
		var id = $(this).attr("id");
		$(".news_big").slideUp();
		$("#news_big_" + id).slideDown();
	});
	$("#back_link_home").click(function () {
		$(".news_big").slideUp("2000", function () {
			$("#home_content").slideDown();
			$("#back_link_home").slideUp();
		});
	});
	
	$.fn.appendVal = function(txt) {
	   return this.each(function(){
	       this.value += txt;
	   });
	};


	$(".bbcode").click(function () {
//		alert($(this).attr("id"));
		$("#news").appendVal($(this).attr("id"));
	});
	
	$(".faq_entry").click (function () {
		$(".faq_a").slideUp(500);
		if ($(this).children(".faq_a").is(":hidden"))
			$(this).children(".faq_a").slideDown(500);
		else
			$(this).children(".faq_a").slideUp(500);
	});

	$.post(
		"index.php",
		{
			ajax: "makeModsOptions",
			game: $("#config_game").val()
		},
		function (data) {
			$("#config_mod").html(data);
			$("#config_mod").show();
		}
	);
	
	if ($("#gallery").length > 0)
	{
		$.get(
			"http://gallerie.ex-pros.de/index.php",
			{
				q: "/EPS+Finals"
			},
			function (data) {
				alert(data);
				$("#gallery").html(data);
			}
		);
//		alert("test");
//		$("#gallery").load("http://gallerie.ex-pros.de/index.php");
//		alert("test");
	}
	
	$("#config_game").change( function () {
		$.post(
			"index.php",
			{
				ajax: "makeModsOptions",
				game: $(this).val()
			},
			function (data) {
				$("#config_mod").html(data);
			}
		);
	});
	
	$("#admin_servertype").change( function () {
		$.post(
			"index.php",
			{
				ajax: "getFieldsForType",
				value: $("#admin_servertype").val()
			},
			function (data) {
				var div = $("#admin_fields");
				
				var content = "<table cellpadding=0 cellspacing=0 border=0>";
				
				for (var i=0; i<data.length; i++)
				{
					if (data[i].disabled == "true")
						var disabled = " readonly=\"readonly\"";
					else
						var disabled = "";
					if (data[i].typ=="textfield")
						content += "<tr><td style=\"padding-bottom: 5px;\">"+data[i].name+"</td><td style=\"padding-bottom: 5px; padding-left: 10px;\"><input name=\""+data[i].name+"\" type=\"text\" value=\""+data[i].value+"\""+disabled+"></td></tr>";
					else if (data[i].typ=="select"){
						content += "<tr><td style=\"padding-bottom: 5px;\">"+data[i].name+"</td><td style=\"padding-bottom: 5px; padding-left: 10px\"><select name=\""+data[i].name+"\""+disabled+">";
						for (var j =0; j<data[i].value.length; j++)
							content += "<option value=\"" + data[i].value[j] + "\">" + data[i].value[j] + "</option>";
						content += "</select></td></tr>";
					}
					else if (data[i].typ=="game")
					{
						content += "<tr><td>"+data[i].name+"</td><td>";
						content += $.post(
							"index.php",
							{
								ajax: "getGamesJson"
							},
							function (games) {
								content += games;
								for (var attrib in games) {
									console.log(attrib + games[attrib]);
									content += "<option value=\"" + attrib + "\">" + attrib + "</option>";
								}
								return content;
							},"json"
						);
						content += "</td></tr>";
					}
				}
				
				content += "</table>";
				
				div.html(content);
			},"json"
		);
	});
	
	$(".showProduct").click(function () {
		$(this).parent().children("div").toggle();
	});

	$("#scrollTop").click(function () {
		$('html, body').animate({scrollTop:0}, 'slow');
		return false;
	});
	
	
	$(".testserver_header").mouseover(function () {
		$(this).parent().children(".testserver_player").show();
		$(this).mouseout(function () {
			$(this).parent().children(".testserver_player").hide();
		});
	});
	
	
	$(".warenkorb_produkt").click(function () {
		$(this).children("div").toggle();
	})
	
	$("#clearBasket").click( function () {
		$.post(
			"index.php",
			{
				ajax: "clearBasket"
			},
			function (data) {
				$("#Warenkorb").slideUp();
			}
		);
	});

	$(".payment_method").hide();
	$("#payment_" + $("#select_payment").val()).show();
	
	$("#select_payment").change(function () {
		$(".payment_method").hide();
		$("#payment_" + $(this).val()).show();
	});
	
	

	
	
	if ($("#gameserver_config").length > 0)
	{
		$("#gameserver_config select").change( function () {
			var price = calculateGameserverPrice("gameserver_config");
			$("#produkt_price").html("nur <span class=\"s22\">" + price + "�</span> im Monat");
			if ($("#gameserver_config #gameserver_lifetime").val() == 1)
				$("#produkt_price").html($("#produkt_price").html() + "<br/><span class=\"s12\">zzgl. 19.95� Einrichtungsgeb�hr</span>");
			else
				$("#produkt_price").html($("#produkt_price").html() + "<br/><span class=\"s12\">Gesamt " + price * $("#gameserver_config #gameserver_lifetime").val() + "�</span>");
			$("#gameserver_price").val(price);
		});
	
		var price = calculateGameserverPrice("gameserver_config");
		$("#produkt_price").html("nur <span class=\"s22\">" + price + "�</span> im Monat");
		if ($("#gameserver_config #gameserver_lifetime").val() == 1)
			$("#produkt_price").html($("#produkt_price").html() + "<br/><span class=\"s12\">zzgl. 19.95� Einrichtungsgeb�hr</span>");
		else
			$("#produkt_price").html($("#produkt_price").html() + "<br/><span class=\"s12\">Gesamt " + price * $("#gameserver_config #gameserver_lifetime").val() + "�</span>");
		$("#gameserver_price").val(price);
	}
	else if ($("#voiceserver_config").length > 0)
	{
		$("#voiceserver_config select").change( function () {
			var price = calculateVoiceserverPrice("voiceserver_config");
			$("#produkt_price").html("nur <span class=\"s22\">" + price + "�</span> im Monat");
			$("#produkt_price").html($("#produkt_price").html() + "<br/><span class=\"s12\">Gesamt " + price * $("#voiceserver_config #voiceserver_lifetime").val() + "�</span>");
			$("#voiceserver_price").val(price);
		});
	
		var price = calculateVoiceserverPrice("voiceserver_config");
		$("#produkt_price").html("nur <span class=\"s22\">" + price + "�</span> im Monat");
		$("#produkt_price").html($("#produkt_price").html() + "<br/><span class=\"s12\">Gesamt " + price * $("#voiceserver_config #voiceserver_lifetime").val() + "�</span>");
		$("#voiceserver_price").val(price);
	}
	else if ($("#tvserver_config").length > 0)
	{
		$("#tvserver_config select").change( function () {
			var price = calculateTvserverPrice("tvserver_config");
			$("#produkt_price").html("nur <span class=\"s22\">" + price + "�</span> im Monat");
			$("#produkt_price").html($("#produkt_price").html() + "<br/><span class=\"s12\">Gesamt " + price * $("#tvserver_config #tvserver_lifetime").val() + "�</span>");
			$("#tvserver_price").val(price);
		});
	
		var price = calculateTvserverPrice("tvserver_config");
		$("#produkt_price").html("nur <span class=\"s22\">" + price + "�</span> im Monat");
		$("#produkt_price").html($("#produkt_price").html() + "<br/><span class=\"s12\">Gesamt " + price * $("#tvserver_config #tvserver_lifetime").val() + "�</span>");
		$("#tvserver_price").val(price);
	}
	else if ($("#streamserver_config").length > 0)
	{
		$("#streamserver_config select").change( function () {
			var price = calculateStreamserverPrice("streamserver_config");
			$("#produkt_price").html("nur <span class=\"s22\">" + price + "�</span> im Monat");
			$("#produkt_price").html($("#produkt_price").html() + "<br/><span class=\"s12\">Gesamt " + price * $("#streamserver_config #streamserver_lifetime").val() + "�</span>");
			$("#streamserver_price").val(price);
		});
	
		var price = calculateStreamserverPrice("streamserver_config");
		$("#produkt_price").html("nur <span class=\"s22\">" + price + "�</span> im Monat");
		$("#produkt_price").html($("#produkt_price").html() + "<br/><span class=\"s12\">Gesamt " + price * $("#streamserver_config #streamserver_lifetime").val() + "�</span>");
		$("#streamserver_price").val(price);
	}
	else if ($("#irc_config").length > 0)
	{
		$("#irc_config select").change( function () {
			var price = calculateIrcPrice("irc_config");
			$("#produkt_price").html("nur <span class=\"s22\">" + price + "�</span> im Monat");
			$("#produkt_price").html($("#produkt_price").html() + "<br/><span class=\"s12\">Gesamt " + price * $("#irc_config #irc_lifetime").val() + "�</span>");
			$("#irc_price").val(price);
		});
	
		var price = calculateIrcPrice("irc_config");
		$("#produkt_price").html("nur <span class=\"s22\">" + price + "�</span> im Monat");
		$("#produkt_price").html($("#produkt_price").html() + "<br/><span class=\"s12\">Gesamt " + price * $("#irc_config #irc_lifetime").val() + "�</span>");
		$("#irc_price").val(price);
	}
	
});


function calculateGameserverPrice(form) {

	var server_art = $("#" + form + " #gameserver_serverart").val();
	if (server_art == "gameserver")
		var price_per_slot = $("INPUT [name=pps_gameserver]").val();

	if (server_art == "extremserver")
		var price_per_slot = $("INPUT [name=pps_extremserver]").val();
	
	
	var price = price_per_slot * $("#" + form + " #gameserver_slots").val();
	
	var server_type = $("#" + form + " #gameserver_servertype").val();
	if (server_type == "publicserver")
		price = price + ($("#" + form + " #gameserver_slots").val() * 1);

	
	var lifetime = $("#" + form + " #gameserver_lifetime").val();

//	if (lifetime == 1)
//		price = price + 19.95;
	
	var payment = $("#" + form + " #gameserver_payment").val()
	if (payment == 6)
		price = price - (5 / 12);
	else if (payment == 12)
		price = price - (10 / 12);

	var rabatt = $("#" + form + " #gameserver_rabatt").val();
	if (rabatt == 0)
		price = price - 5;

	if (lifetime == 6)
		price = price - price * 0.05;
	else if (lifetime == 12)
		price = price - price * 0.10;

	return price.toFixed(2);
}


function calculateVoiceserverPrice(form) {
	var server_art = $("#" + form + " #voiceserver_serverart").val();
	if (server_art == "teamspeak")
		var price_per_slot = "0.35";

	if (server_art == "mumble")
		var price_per_slot = "0.35";

	if (server_art == "shockvoice")
		var price_per_slot = "0.35";

	if (server_art == "ventrilo")
		var price_per_slot = "0.35";
	
	var price = price_per_slot * $("#" + form + " #voiceserver_slots").val();
	

	
	return price.toFixed(2);
}


function calculateTvserverPrice(form) {
	
	var price_per_slot = "0.40";

	var price = price_per_slot * $("#" + form + " #tvserver_slots").val();
	
	return price.toFixed(2);
}


function calculateStreamserverPrice(form) {
	
	var price_per_slot = "0.55";

	var price = price_per_slot * $("#" + form + " #streamserver_slots").val();
	
	return price.toFixed(2);
}


function calculateIrcPrice(form) {

	var server_art = $("#" + form + " #irc_serverart").val();
	var price = 0;
	
	if (server_art == "bnc") {
		$("#" + form + " #irc_anzahl").show();

		var slots = $("#" + form + " #irc_slots").val();

		if (slots == 1)
			var price_per_slot = "0.65";
		else if (slots < 6)
			var price_per_slot = "0.60";
		else if (slots < 11)
			var price_per_slot = "0.50";
		else
			var price_per_slot = "0.45";

		price = price_per_slot * slots;

		$(".produkt_bestellen").show();
	}
	else
	{
		$("#" + form + " #irc_anzahl").hide();
		$(".produkt_bestellen").hide();
		return "1.50";
	}
	
	return price.toFixed(2);
}

