$(document).ready(function(){
	if (document.all && typeof document.body.style.maxHeight == "undefined") { //IE6:
		$("p + p").addClass("ie6fix1");
		$("p + ul").addClass("ie6fix1");
		$("ul + p").addClass("ie6fix1");
		$("p + ol").addClass("ie6fix1");
		$("ol + p").addClass("ie6fix1");
		$("li + li").addClass("ie6fix2");
		$(".dokumentenliste + .linkliste").addClass("ie6fix3");
		$(".wysiwyg").find("td + td").addClass("ie6fix4");
	} else { // no IE6:
		$(".submenu").mouseover(function(){
			$(this).prev("a").addClass("hover");
		});
		$(".submenu").mouseout(function(){
			$(this).prev("a").removeClass("hover");
		});
	}
	
	$("#sidebar,#content").wrapAll("<div id='contentwrap'></div>");
	
	$("#keylink").attr("href","/wecos/admin.html");
	$("#keylink").attr("target","_blank");
	
	$(".warndialog").css("position","absolute");
	$(".warndialog").find("a.ok").css("display","block");

	$(".alternAuto").each(function(i){
		if (i%2) $(this).addClass("altern2");
		else $(this).addClass("altern1");
	});
	
	$(".scrollpane").jScrollPane({showArrows:true, scrollbarWidth: 20, arrowSize: 20});
	
	$("#contentspalte-default-rechts").find("span:contains('@')").text("@ ");
	//$("#content").find("h6").before('<span class="plaketteNeu"></span>');
	
	if ($("#textblock").height() > $("#textblockmaxheight").height()) {
		$("#textblock").css("height","3.96em").css("overflow","hidden");
		$("#textblockzusaetze").css("display","block");
		$("#textblockzusaetze").find("a.dialoglink").click(function(){
			$("#textblockkomplett").hide().removeShadow().fadeIn('fast',function(){ 
				$(this).dropShadow({opacity:0.2});
			});
			this.blur();
			return false;
		});
	}
	
	jQuery.fn.extend({ 
		autoclear: function() { 
			return this.each(function(){
				if($(this).val()==""&&$(this).attr("title")!=""){
					$(this).val($(this).attr("title"));
					$(this).focus(function(){
						if($(this).val()==this.title) $(this).val("");
					});
					$(this).blur(function(){
						$(this).autoclear();
					});
				}
			}); 
		} 
	});	
	$("#login").find("form").submit(function(){
		$(".autoclear").each(function(){
			if($(this).val()==$(this).attr("title")) $(this).val("");
		});
		return true;
	});
	$(".autoclear").autoclear();
	
	$("a.empfehlen").click(function(){
		if(this.href!="") {
			if($("#empfehlen").html()!="") {
				$("#empfehlen").slideUp(function(){
					$(this).html("");
					$(this).attr("rel","");
				});
			} else {
				$("#empfehlen").ajaxComplete(function(){ 
					if($(this).attr("rel")!="auf") {
						$(this).slideDown();
						$.scrollTo("#empfehlen",700);
						$(this).attr("rel","auf");
					} else {
						$(this).fadeTo("fast", 1.0);
					}
				});
				$("#empfehlen").load(this.href);
			}
		}
		return false;
	});	
	
	jQuerySendForm = function(pFrom,pCont) {
		if (!pFrom || !pCont) return;
		$("input[@name='vorlage']", pFrom).val("ajax");
		var tmpParams = "";
		for (var i=0; i<pFrom.elements.length; i++) {
			if (pFrom.elements[i].type=="checkbox") {
				if (pFrom.elements[i].checked) tmpParams = tmpParams + "&" + pFrom.elements[i].name + "=" + pFrom.elements[i].value;
			} else if (pFrom.elements[i].type=="radio") {
				if (pFrom.elements[i].checked) tmpParams = tmpParams + "&" + pFrom.elements[i].name + "=" + pFrom.elements[i].value;
			} else {
				tmpParams = tmpParams + "&" + pFrom.elements[i].name + "=" + pFrom.elements[i].value;
			}
		}
		//$("#"+pCont).css({ cursor: "wait" });
		$("#"+pCont).fadeTo("fast", 0.2);
		//$(pFrom).css({ cursor: "wait" });
		$.ajax({ 
			type: "POST", 
			url:  pFrom.action, 
			data: tmpParams,
			success: function(msg){ 
				$("#"+pCont).html(msg);
			}
		});
		//$("#"+pCont).css({ cursor: "auto" });
		//$(pFrom).css({ cursor: "auto" });
	}
	jQueryAjax = function(pUrl,pCont) {
		if (!pUrl || !pCont) return;
		//$("#"+pCont).css({ cursor: "wait" });
		$.ajax({ 
			type: "GET", 
			url:  pUrl,
			success: function(msg){ 
				$("#"+pCont).html(msg);
			}
		});
		//$("#"+pCont).css({ cursor: "auto" });
	}
	
});
