function getEl (id) {
	return document.getElementById(id);
}
Array.prototype.in_array = function(needle) {
	for(var i=0; i < this.length; i++)
		if(this[i] == needle) return true;
		else if (this[i].in_array) {
		if (this[i].in_array(needle)) return true;
	}
	return false;
}
$(document).ready(function () {
    
    // $('div#nav_main a').each(function (i) {
    //     $(this).css('display', 'none');
    // }
    
    // $('div#nav_main li').css('display', 'none');
    // speed = 50;
    // $('div#nav_main li').each(function(){
    //     speed = speed+50;
    //     $(this).fadeIn(speed);
    // });

    // $('div#stuecke_liste a').css('display', 'none');

    // $('div#stuecke_liste a').each(function(i){
    //     this.id = 'stuecke_liste'+i;
    // });
    // 
    // function viewSTK() {
    //     $('#stuecke_liste'+i).fadeIn(350);
    //     i++;
    //     
    //     console.log("%s", '#stuecke_liste'+i);
    // }
    // i = 0;
    // var aktiv = window.setInterval("viewSTK()", 500);
    $('div#stuecke_liste').slideDown("slow");
    

    $('div#nav_main').css('display', 'none');
    $('#nav_main li#mtheater ul').css('display', 'none');
    $('#nav_main li#mstuecke ul').css('display', 'none');
    $('#nav_main li#mbuchen ul').css('display', 'none');
    $('#nav_main li#mservice ul').css('display', 'none');
    // $('#nav_main li ul li').css('display', 'none');
    
	var href = window.location.href;
	var protocol = window.location.protocol;
	var host = window.location.host;
	var path = window.location.pathname;
	var base_url = protocol+'//'+host;
	var segment1 = protocol+'//'+host+'/'+path.split('/')[1];
	// var segment1 = '/'+path.split('/')[1];

	// $('div#nav_main li a').each(function(i){
	// 	eval($(this+':parent')).id = "m_"+eval(this.href.split('/')[1]);
	// 	// alert('m' + eval($(this + ' > a')).attr('href').split('/')[1]);
	//  });
	
	if(path.indexOf('/theater') == -1){
		$('li#mtheater').mouseover(function(){ $('li#mtheater ul').css('display','inline'); });
		$('li#mtheater').mouseout( function(){ $('li#mtheater ul').css('display','none'); });
	} else { $('li#mtheater ul').css('display','inline'); }

	if( path.indexOf('/stuecke') == -1 &&
	    path.indexOf('/workshops') == -1 &&
	    path.indexOf('/inszene') == -1 &&
	    path.indexOf('/projekte') == -1 ){
		$('li#mstuecke').mouseover(function(){
		    $('li#mstuecke ul').css('display','inline');
    		$('a.stk_main').css('display','none');
    		$('a.stk_first').css('display','inline');
		});
		$('li#mstuecke').mouseout( function(){
		    $('li#mstuecke ul').css('display','none');
    		$('a.stk_main').css('display','inline');
    		$('a.stk_first').css('display','none');
		});
	} else {
	    $('li#mstuecke ul').css('display','inline');
	    $('a.stk_main').css('display','none');
	}
	if(path.indexOf('/buchen') == -1){
		$('li#mbuchen').mouseover( function(){ $('li#mbuchen ul').css('display','inline'); });
		$('li#mbuchen').mouseout(  function(){ $('li#mbuchen ul').css('display','none'); });
	} else { $('li#mbuchen ul').css('display','inline'); }
	
	if(path.indexOf('/service') == -1){
		$('li#mservice').mouseover(function(){
		    $('li#mservice ul').css('display','inline');
    		$('a.service_main').css('display','none');
		});
		$('li#mservice').mouseout( function(){
		    $('li#mservice ul').css('display','none');
            $('a.service_main').css('display','inline');
		});
	} else {
	    $('li#mservice ul').css('display','inline');
        $('a.service_main').css('display','none');
	}

	$('div#nav_main a').each(function(i){
        // s1 = path.split('/')[1];
        s2 = path.split('/')[2];
	  	if(	this.href == href ||
	  	    this.href.indexOf(s2) > -1 ){
			this.id = 'current';
		}
	});

    s1 = path.split('/')[1];
    if(s1 == 'tourneeplan'){
     $('#tourneeplan a').addClass('current');
    }
    if(s1 == 'stuecke' && path.indexOf('bildergalerie') == -1){
     $('a.stk_first').addClass('current');
    }
    if( s1 == 'workshops' ||
        s1 == 'inszene' ||
        s1 == 'projekte'){
     $('a.stk_projects').addClass('current');
    }
    $('div#nav_main').css('display', 'block');

    // function changeFormValues ( elem ) {
    //     $(elem).each(function (i) {
    //         txt_val = $(this).val();
    //         if(txt_val.search(/&(.*);/gi) > -1){
    //             new_strg = txt_val.replace(/&(.*);/gi, '&$1');
    //             $(this).val(new_strg);
    //         };
    //     });
    // }
    // function changeTxtValues ( elem ) {
    //     $(elem).each(function (i) {
    //         txt_val = $(this).html();
    //         if(txt_val.search(/&(.*);/gi) > -1){
    //             new_strg = txt_val.replace(/&(.*);/gi, '&$1');
    //             $(this).html(new_strg);
    //         };
    //     });
    // }
    
    function changeFormValues ( elem ) {
        $(elem).each(function (i) {
            txt_val = $(this).val();
            if(txt_val.search(/Hin&Weg;.sehen/gi) > -1){
                new_strg = txt_val.replace(/Hin&Weg;.sehen/gi, 'Hin&Weg.sehen');
                $(this).val(new_strg);
            };
        });
    }

    // alert (window.location.href.indexOf('/modify/'));
    // if (window.location.href.indexOf('/modify/') < -1){
    //     // Hin&Weg.sehen ID 1000080
        $("span:contains('Hin&Weg;.sehen')").html('Hin&Weg.sehen');
        $("a:contains('Hin&Weg;.sehen')").html('Hin&Weg.sehen');
        $("h2:contains('Hin&Weg;.sehen')").html('Hin&Weg.sehen');
        $("td:contains('Hin&Weg;.sehen')").html('Hin&Weg.sehen');
        $("option:contains('Hin&Weg;.sehen')").html('Hin&Weg.sehen');
        $("label:contains('Hin&Weg;.sehen')").html('Hin&Weg.sehen');
        $("img[title=Hin&Weg;.sehen]").attr('title', 'Hin&Weg.sehen');
        $("img[alt=Hin&Weg;.sehen]").attr('alt', 'Hin&Weg.sehen');
        // $("textarea:contains('Hin&Weg;.sehen')").html('Hin&Weg.sehen');
        changeFormValues ( "textarea" );
        changeFormValues ( "input" );
    // }
    // $("input[value=Hin&Weg;.sehen]").attr('value', 'Hin&Weg.sehen');
    
    $("span.gallery a").lightBox();

	  $('input[type=checkbox], input[type=radio]').css({'width':'1.5em', 'height':'1.5em'});
});


this.imagePreview = function(show_title){
    show_title = (show_title!=undefined) ? show_title : false;	
	/* CONFIG */
		
		xOffset = 10;
		yOffset = 30;
		
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
    // tstamp = new Date().getTime();
	$("a.preview").hover(function(e){

        var c ='';
		this.t = this.title;

	    t = this.t.split('/');
	    c = t[t.length-1];
	    src = this.t.replace('', c);

		this.title = "";
			
        c = (c!="" && show_title!=false) ? "<br/>" + c : "";

        // $("body").append("<p id='preview'><img src='"+ this.t +"?"+ tstamp + "' alt='' />"+ c +"</p>");
        // $("body").append("<p id='preview'><img src='"+ this.t +"' alt='' />"+ c +"</p>");
        $("body").append("<p id='preview'><img src='"+ this.t +"' alt='' />"+ c +"</p>");
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")
			.fadeIn("fast");						
    },
	function(){
		this.title = this.t;	
        $("#preview").remove();
    });	
	$("a.preview").mousemove(function(e){
		$("#preview")
			.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px");
	});			
};

chkForm = function () {
	var r = false;
	email	= $('#email').val();
	strasse	= $('#strasse').val();
	plz_ort	= $('#plz_ort').val();
	telefon	= $('#telefon').val();
	if (
		email!='' ||
		(strasse!='' && plz_ort!='') ||
		telefon!=''
	) { r = true; } else {
		$('#info').html('Bitte geben Sie Ihre E-Mail, Telefonnummer oder Adresse ein.');
		$('#info').fadeIn(100);
	}
	$('#info').fadeOut(10000);
	return r;
}

chkSecureForm = function () {
    
    $('input').each(function (i) {
        this.id = this.name;
    })
    
	var r = false;
	email	= $('#email').val();
	strasse	= $('#strasse').val();
	plz_ort	= $('#plz_ort').val();
	telefon	= $('#telefon').val();
	
    // console.log("1%s 2%s 3%s 4%s", email, strasse, plz_ort, telefon);
    // return false;
	
	if ( email=='' && (strasse=='' && plz_ort=='') && telefon=='' ) {
        // $('#email').css('border', '1px solid #f00').focus();
        // $('#strasse').css('border', '1px solid #f00').focus();
        // $('#plz_ort').css('border', '1px solid #f00').focus();
        // $('#telefon').css('border', '1px solid #f00').focus();
		alert('Bitte geben Sie Ihre E-Mail, Telefonnummer oder Adresse ein.\n\nIhr Theater-Spiel Team');
		r = false;
	} else {
	    r = true;
	}
    
	s = $('#sicherheitscode').val();
	if(s==''){
		$('#sicherheitscode').css('border', '1px solid #f00').focus();
		alert('Helfen Sie uns mit Spam zu vermeiden.\nBitte rechnen Sie das Ergebnis der Sicherheitsgrafik aus und geben Sie es in das rot umrandete Feld ein.\n\nIhr Theater-Spiel Team');
		r = false;
	} else {
		r = true;
	}
	return r;

}


function ExecuteCommand( commandName, txtInstance )
{
	var oEditor = FCKeditorAPI.GetInstance( txtInstance ) ;
	oEditor.Commands.GetCommand( commandName ).Execute() ;
}


function mYm(){
	document.write('E-Mail: <a href="mailto:info'+'@'+'theater-spiel.de">info'+'@'+'theater-spiel.de</a>');
}
function mail(pref, domain) {
	window.location = "mailto:" + pref + "@" + domain;
}


function txt(cid, content, type)
	{
		displayWindow=window.open("/presse_showtext.php?cid="+cid+"&content="+content+"&type="+type, "displayWindow","toolbar=no,width=640,height=400,directories=no,status=no,scrollbars=yes,resize=no,menubar=no");
		//displayWindow.focus();		
	}



wmtt = null;

document.onmousemove = updateWMTT;

function updateWMTT(e) {
	x = (document.all) ? window.event.x + document.body.scrollLeft : e.pageX;
	y = (document.all) ? window.event.y + document.body.scrollTop  : e.pageY;
	if (wmtt != null) {
		wmtt.style.left = (x + 20) + "px";
		wmtt.style.top 	= (y + 20) + "px";
	}
}

function showWMTT(text) {
	wmtt = document.getElementById('tooltip');
  wmtt.innerHTML = text;
	wmtt.style.display = "block";
}

function hideWMTT() {
	wmtt.style.display = "none";
}

currentmedia = "";

function play_flash(name) {
  if(currentmedia == "" || currentmedia != name) {
  	flashtag = '<OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" WIDTH="1" HEIGHT="1" CODEBASE="http://active.macromedia.com/flash5/cabs/swflash.cab#version=5,0,0,0"><PARAM NAME="movie" VALUE="media/' + name +'"><PARAM NAME="play" VALUE="true"><PARAM NAME="loop" VALUE="false"><PARAM NAME="quality" VALUE="low"><EMBED SRC="media/' + name +'" WIDTH="1" HEIGHT="1" quality="low" loop="false" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></EMBED></OBJECT>';
    currentmedia = name;
	  document.getElementById('media').innerHTML = flashtag;
  }
}
function stop_flash() {
	document.getElementById('media').innerHTML = '';
  currentmedia = "";
}

	function showptxt(stueck)
	{
		msgWindow=window.open("popups/showpressetext.php?stueck="+stueck, "displayWindow","toolbar=no,width=640,height=400,directories=no,status=no,scrollbars=yes,resize=no,menubar=no")
	}
  function showtextauszuege(stueck)
	{
		msgWindow=window.open("popups/showtextauszuege.php?stueck="+stueck, "displayWindow","toolbar=no,width=640,height=400,directories=no,status=no,scrollbars=yes,resize=no,menubar=no")
	}
	function showkrit(stueck)
	{
		msgWindow=window.open("kritiken/krit" + stueck + ".html", "displayWindow","toolbar=no,width=640,height=400,directories=no,status=no,scrollbars=yes,resize=no,menubar=no")
	}

