///////////////////////////////////////////
///////////////// Wizard /////////////////
/////////////////////////////////////////

var timeout_text;
var wizard_state = "openend";

function sleep_js () {

	setTimeout('init_wizard()',0)

}


function init_wizard () {

	//var pos_x = (window.innerWidth / 2);
	//var pos_y = (window.innerHeight / 2);
	

	//var content_offset = $("#content").offset();
	//var pos_x = content_offset.Top;
	//var pos_y = content_offset.Left;
	var pos_x = document.getElementById("content").offsetLeft - 210;
	var pos_y = document.getElementById("content").offsetTop + 10;
	//document.getElementById("content")
	//alert("pos_x: " + pos_x + " / pos_y: " + pos_y);
	$("#footer").after("<div id=\"wizard\"><div id=\"wizard_hide_show\"><a href=\"#\" title=\"Wizard schlie&szlig;en...\" id=\"wizard_show_hide_a\" onkeyup=\"show_hide_wizard()\" onmouseup=\"show_hide_wizard()\"><img src=\"img/wizard_hide.png\" width=\"16\" height=\"16\" id=\"wizard_show_hide_img\" alt=\"wizard_show_hide\"></a></div><div id=\"wizard_content\"><p id=\"wizard_text\">Wizard</p><p id=\"wizard_fail_text\"></p></div></div>");
	$("#wizard").css({ top: pos_y, left: pos_x, display: "block"})
	$("#wizard").draggable({ containment: 'document' });
	
	if ($("#fail_hidden").val() != "") {
	
		set_std_wizard_text();
		$("#wizard_fail_text").html($("#fail_hidden").val());
	
	}
	else {
		
		set_std_wizard_text();
	
	}
	
}


function get_set_wizard_text (element, std) {
	
	if (std == true) {
		
		set_std_wizard_text();
	
	}
	else {
	
	clearTimeout(timeout_text);
	var event_sender = element.id
	var data_string = "field_id=" + event_sender;

	$.ajax({
		method: "get",
		url: "php/Wizard.php",
  		data: data_string,
		dataType: "xml",
		cache: false,
		error: function (xhr, desc, exceptionobj) { alert(xhr.responseText);},
		
		beforeSend: function(){
			
			//jQuery("#fabric_search_content_loading_div").show();
			//jQuery("#fabric_search_content_div").hide();
			
		},
		complete: function(){},
		success: function(xml){ 	
					
			//jQuery("#fabric_search_content_loading_div").fadeOut("fast");
			//jQuery("#fabric_search_content_div").show();

			//wizard_text = xml.getElementsByTagName("wizard_text")[0].firstChild.nodeValue;
			wiz_text = $(xml).find("wizard_text").text();
			
			$("#wizard_text").html(wiz_text);
		
		}
	
		
	}); //close jQuery.ajax(*/	
	
	}
	
}


function clean_wizard_text () {
	
	timeout_text = setTimeout('get_set_wizard_text("",true)',1000);
	
}


function set_std_wizard_text () {

	$("#wizard_text").text("Ich bin der tolle Wizard, der Ihnen durch das Formular hilft.")	

}


function show_hide_wizard () {
	
	$("#wizard_content").slideToggle("fast");
	
	if (wizard_state == "opened") {
		
		get_set_wizard_text("",true);
		
		wizard_state = "closed";
		
	}
	else {
		
		wizard_state = "opened";
		
	}
	

	if ($("#wizard_show_hide_a").attr("title") == "Wizard schließen...") {

		$("#wizard_show_hide_a").attr({ title: "Wizard öffnen..."});
		
	}
	else {
		
		$("#wizard_show_hide_a").attr({ title: "Wizard schließen..."});
		
	}

	
	if ($("#wizard_show_hide_img").attr("src") == "img/wizard_show.png") {
	
		$("#wizard_show_hide_img").attr({ src: "img/wizard_hide.png"});
		
	}
	else {
		
		$("#wizard_show_hide_img").attr({ src: "img/wizard_show.png"});
		
	}
		
}


/*$(function() {

    $('input[type=radio]').focus(function() {

      //$(this).val() == '';
		alert("test");
      });

 });*/
