/* MENUE global values */

var MENUE_movin = false;
var MENUE = ""
var _mx = "-240px";

function prepare_document() {
	
    //main menue
    MENUE = $('#MENUE')
	MENUE.mouseover(function() { moveIn(); });
    $("#startpanel, #main, #footer").mouseover(function() { moveOut(); });
    
	var q = document.location.search;
	//var i = q.indexOf('MENUEOPEN=1');
	var i = q.indexOf('mo=1');



    if (i == -1) {
      MENUE.css("left", _mx);
	} else {
      MENUE.css("left", "0px");
	}
	
	//buttons
	$(".tabs a, a.button, a.button2go, a.superbutton, a.superbutton2go, a.flatbutton, a.flatbutton2go").mouseup(function() { $(this).blur(); });
	//boxes
	$(".box .hd a.close").click(function(){
		close_box($(this).parents("div.box")[0]);
 	});
	$(".box .hd a.open").click(function(){
		open_box($(this).parents("div.box")[0]);
 	});
 	$(".box .hd a.open").fadeOut(500);
 	
 	$(".box#closed").each( function() {
 		close_box($(this));
 	}	
 	);
	//forms
	$("form.standard a.submit").click( function() { submit_form($($(this).parents("form")[0])) } );
	$("form.standard a.reset").click( function() {reset_form($($(this).parents("form")[0]))} );
	$("form.standard textarea, form.standard input, form.standard select, form.searchfield input.text").each(function() {
		if(this.tagName.toLowerCase() == 'textarea' || this.tagName.toLowerCase() == 'input') {
			this.setAttribute('init_value', this.value)
		}
		this.onfocus = function() { focus_form_element($(this)); };
	});
	$("form.searchfield input.text").each( function() {
		this.onblur =  function() { refill_searchfield($(this)); $(this).removeClass("focus")};
	});
	/* for the f.cking IE, which will never support web standards -- even if they are as old as the web */
	/* this is commonly done by a simple tag:hover css statement *grmpf* */
	$('#MENUE ul li').each( function() {
		this.onmouseover = function() {$(this).addClass('hover');}
		this.onmouseout = function() {$(this).removeClass('hover');}
	});
    jQuery("div#slider1").codaSlider();
    // jQuery("div#slider2").codaSlider()
    // etc, etc. Beware of cross-linking difficulties if using multiple sliders on one page.
    
	$('#acc1').accordion({
         active: '.selected', 
         selectedClass: 'active',
         animated: "bounceslide",
         header: "dt",
         autoheight: true
       }    
    );
    
    //shadows
    $(".dropshadow").wrap("<div class='sw0'><div class='sw1'><div class='sw2'>" + "<div class='sw3'></div></div></div></div>");
    
    //tables
    $("table.alternate tr:odd").addClass("odd");
    $("table.alternate tr:even").addClass("even");
    
    $("a.link_icon").after("<i></i>");
}

//boxes
function close_box(n) {
	$(".bd .c", n).slideUp("slow");
	$(".hd .controls a.open", n).fadeIn(500);
	$(".hd .controls a.close", n).fadeOut(500);
}
function open_box(n) {
	$(".bd .c", n).slideDown("slow"); 
	$(".hd .controls a.open", n).fadeOut(500);
	$(".hd .controls a.close", n).fadeIn(500);
}

//forms
function focus_form_element(n) {
	$('form .focus').removeClass('focus');
	n.removeClass("alert");
	n.addClass('focus');
	n.parents(".label").addClass("focus");
	n.prev(".label").addClass("focus");
	var tn = n.get(0).tagName;
	if (tn.toLowerCase() == "textarea" || tn.toLowerCase() == "input") {
		if (n.val().toLowerCase() == n.attr('init_value').toLowerCase()) {
			n.val("");
		}
	}	
}
function reset_form(n) {
	$(".alert", n).removeClass("alert");
	$(".focus", n).removeClass("focus");
	n.get(0).reset();
}
function submit_form(n) {
	var failure = false;
	$(".focus", n).removeClass("focus");
	$("input, textarea", n).each( function() {
		if(this.value == this.getAttribute('init_value')) {
			$(this).addClass('alert');
			failure = true;
		}
	} );
	$("textarea.notempty, input.notempty", n).each( function() {
		if(this.value == "") {
			$(this).addClass('alert');
			failure = true;
		}
	} );
	if(!failure) n.get(0).submit();
}
function refill_searchfield(n) {
	if(n.val() == "") { n.val(n.attr('init_value')) }
}

function surfto(select_tag)
{
	var myindex = select_tag.selectedIndex
	if (select_tag.options[myindex].value != "0")
	{
		alert(select_tag.options[myindex].value);
		//window.location=select_tag.options[myindex].value;
	}
}

/* MAIN MENU */

function moveIn() {
	if ( MENUE_movin == false && MENUE.css('left') == _mx ) {
		MENUE_movin = true;
		MENUE.animate( {left: 0}, 250, 'swing', function(){ MENUE_movin=false; });
	}
}
function moveOut() {
	if ( MENUE_movin == false && MENUE.css('left') == '0px' ) {
		MENUE_movin = true
		MENUE.animate( {left: parseInt(_mx.replace("px"))}, 250, 'swing', function(){ MENUE_movin=false; });
	}
}
