function pageLoad(sender, args) {
  // x_error
  if($(this).hasClass('x_error') == true) {
    $(conf).hide();
    var nuco = $(conf).html();
    var nurl = window.location.href;
    var getval = nurl.split('&');
    if(getval[1] == 'value='+use){
      $('#ctl00_ContentPlaceHolder1_Label1').html(nuco);
    }      
    $(conf).remove();
  }
}

$(document).ready(function() {
  $('#translations').hide();  
  $('a.x_conf').each(function() {
    // variablen
    var use = $(this).attr('title');
    var to = $(this).attr('target');
    var style = $(this).attr('style');
    var src = $(this).attr('src');
    var type = $(this).attr('type');
    var conf = $(this).text();
    
    // x_pos
    if($(this).hasClass('x_bg') == true) {
      $(use).addClass(conf);
    }
    // x_error
    if($(this).hasClass('x_error') == true) {
      var nuco = $(conf).html();
      var nurl = window.location.href;
      var getval = nurl.split('&');
      if(getval[1] == 'value='+use){
        $('#ctl00_ContentPlaceHolder1_Label1').html(nuco);
      }      
      $(conf).remove();
    }
    // slideshow nSlide
    if($(this).hasClass('nSlide')==true){
      var c_slides = $(use).length;
      var SID = 1;
      var rel = $(this).attr('rel');
      $(use).wrapAll('<div id="'+to+'_holder" style="overflow:hidden;"></div>');
      $('#'+to+'_holder').wrap('<div id="'+to+'" style="width:auto; float:left;"></div>');
      $(use).each(function(){
        if(rel=='pcfGalerie'){
          var orisrc = $(this).attr('src');
          var nusrc = orisrc.replace('value=12','value=11');
        }
        $(this).attr('src',nusrc);
        $(this).attr('id',to+'_'+SID);
        SID++;
      });
      var cur = 1;
      $(use).hide();
      var showtime = parseFloat(type,0);
      $(use+'#'+to+'_'+cur).show();
      function loop(){
        $(use+'#'+to+'_'+cur).show(showtime);
        cur++;
        $(use).fadeOut('slow').delay(600);
        if(cur == c_slides+1){
          cur = 1;
          $(use+'#'+to+'_'+cur).fadeIn('slow');
        } else {
          $(use+'#'+to+'_'+cur).fadeIn('slow');
        }
        setTimeout(loop,showtime);
      }
      if(conf=='controls') {
        $('#'+to).append('<div id="'+to+'_ctrl"></div>');
        $('#'+to+'_ctrl').append('<input type="button" disabled="disabled" class="'+to+'_disabled" id="'+to+'_prev" value="<<" />');
        $('#'+to+'_ctrl').append('<input type="button" id="'+to+'_next" value=">>" />');
        $('#'+to+'_next').click(function(){
          $(use+'#'+to+'_'+cur).fadeOut('slow', function() {
            cur++;
            if(cur == c_slides){
              $('#'+to+'_next').attr('disabled','disabled');
              $('#'+to+'_next').addClass(to+'_disabled');
            } else if (cur == 1){
              $('#'+to+'_prev').removeAttr('disabled');
              $('#'+to+'_prev').addClass(to+'_disabled');
            } else if (cur > 1 && cur < c_slides) {
              $('#'+to+'_next').removeAttr('disabled');
              $('#'+to+'_prev').removeAttr('disabled');
              $('#'+to+'_next').removeClass(to+'_disabled');
              $('#'+to+'_prev').removeClass(to+'_disabled');
            }
            $(use+'#'+to+'_'+cur).fadeIn('slow');
          });
        });
        $('#'+to+'_prev').click(function(){
          $(use+'#'+to+'_'+cur).fadeOut('slow', function() {
            cur--;
            if(cur == 1){
              $('#'+to+'_prev').removeAttr('disabled');
              $('#'+to+'_prev').addClass(to+'_disabled');
            } else if (cur == c_slides){
              $('#'+to+'_next').attr('disabled','disabled');
              $('#'+to+'_next').addClass(to+'_disabled');
            } else if (cur > 1 && cur < c_slides) {
              $('#'+to+'_next').removeAttr('disabled');
              $('#'+to+'_prev').removeAttr('disabled');
              $('#'+to+'_next').removeClass(to+'_disabled');
              $('#'+to+'_prev').removeClass(to+'_disabled');
            }
            $(use+'#'+to+'_'+cur).fadeIn('slow');
          });
        });
      } else if(conf=='auto') {
        var cur = 0;
        loop();
      }
    }
    
    // slideshow x_slide
    if($(this).hasClass('x_slide') == true) {
      $(use).wrapAll('<div id="'+to+'"><div id="slideshowWindow"></div></div>');
       var curpos = 0;
       var slidewidth = parseFloat(style,0);
       var slides = $(use);
       var count = slides.length;
       var slideinterval;
       var speed0 =  parseFloat(type,0);
       var speed = parseFloat(conf,0);
       $('#'+to+' #slideshowWindow').css({'width':slidewidth,'overflow':'hidden'});
       $('#'+to+' #slideshowWindow '+use).css({'width':slidewidth});
       slideinterval = setInterval(changePosition, speed);
       slides.wrapAll('<div id="slidesholder"></div>');
       slides.css({'float':'left'});
       $('#'+to+' #slidesholder').css('width', slidewidth * count);
       function changePosition() {
        if(curpos == count - 1) {
        	curpos = 0;
        } else {
        	curpos++;
        }
        moveSlide();
      }
      function moveSlide() {
			 $('#'+to+' #slidesholder').animate({'marginLeft' : slidewidth*(-curpos)}, speed0);
	    }
    }
    
    // x_lang
    if($(this).hasClass('x_lang')==true){
      $('.lingua').hide();
      var syslang = navigator.language;
      switch(conf){
        case 'on':
          $('.'+syslang).show();
          break;
      }
    }
    
    // x_index
    if($(this).hasClass('x_index')==true){
      if(conf=='on'){
        $(use).prepend('<div id="aib"><div id="xdrive">'+to+'</div><ul id="ail"></ul></div>');
        $('#aib').css({'position':'fixed',
        'background':'#fff',
        'border':'2px solid #444',
        'padding':'3px'});
        $('#xdrive').css({'color':'#fff',
        'font-weigth':'bold',
        'background':'#5577FF',
        'padding':'3px',
        'text-align':'center'
        });
        var hx = 1;
        $(use+' h1,'+use+' h2,'+use+' h3,'+use+' h4,'+use+' h5,'+use+' h6').each(function(){
          $(this).addClass('hx');
        });
        $(use+' .hx').each(function() {
          $(this).attr('name','hx'+hx);
          $(this).attr('id','hx'+hx);
          var hp = $('#hx'+hx).position();
          var aiurl = $(this).attr('name');
          var aitxt = $(this).text();
          $('#ail').append('<li><a class="ai" href="#'+aiurl+'" coords="'+hp.top+'">'+aitxt+'</a></li>');
          hx++;
        });
        $('.ai').each(function(){
          $(this).click(function(){
            var scroto = $(this).attr('coords');
            $(use).animate({scrollTop:scroto-40},type);
          });
        });
        /*$('#xdrive').mousedown(function(){
          $('#aib').draggable();
        });*/
      }
    }
    
    // x_off
    if($(this).hasClass('x_off') == true) {
      if(type == 'id') {
        $('#'+to).find(conf+':contains('+use+')').remove();
      } else if(type == 'class') {
        $('.'+to).find(conf+':contains('+use+')').remove();
      }  
    }
    // classes & ids
    if($(this).hasClass('x_claid') == true) {
			var countx = 1;
			switch(type) {
				case 'class':
					var call = $(use).find(to);
					call.addClass(conf);
					break;
				case 'id':
					$(use+' '+to).each(function() {
						$(this).attr('id',conf+countx);
						countx++;
					});				
					break;
			}		
    }
    // new Position
    if($(this).hasClass('x_pos') == true) {    
      if(conf == 'first') {
        if(type != '') {
         use = $('#'+type).find('a:contains('+use+')');    
         $(use).prependTo(to);
        } else {
          $(use).prependTo(to);
        }
      } else if (conf == 'last') {
        if(type != '') {
          use = $('#'+type).find('a:contains('+use+')');
          $(use).appendTo(to);
        } else {
          $(use).appendTo(to);
        }       
      } else {
        if(type != '') {
          use = $('#'+type).find('a:contains('+use+')');
          var xchild = $(to).children()[0].tagName;
  				var npos = parseInt(conf)-1;
  				var pos = xchild+':nth-child('+npos+')';
  				$(use).appendTo(pos);
        } else {
  				var xchild = $(to).children()[0].tagName;
  				var npos = parseInt(conf)-1;
  				var pos = xchild+':nth-child('+npos+')';
  				$(use).appendTo(pos);
  			}
			} 
    }
    
    // new background
    /*if($(this).hasClass('x_bg') == true) {
      if(conf != undefined) {
        var xbg = 'url('+conf+')'+style;
        $(use).attr('style', 'background: '+xbg+';');
      } else {
         $(use).css({'background-color':style});
      }
    }*/
    // themes   
    if($(this).hasClass('x_theme') == true) {      
      switch (type) {
        case 'dl':
          var cdt = 1;         
          var cdd = 1;
          $(use).children('dt').each(function() {
            $(this).attr('target', 'theme_'+cdt);
            $(this).addClass('_read');
            cdt++;
          });
          $(use).children('dd').each(function() {
            $(this).attr('id', 'theme_'+cdd);
            $(this).addClass('_chapter');
            $(this).slideUp();
            cdd++;
          });
          function subit() {
            $('._chapter').each(function() {
              var csub = 1;
              $(this).children('dl').each(function() {
                $(this).addClass('_sub');
                $(this).attr('id', '_sub'+csub);
                var aid = $(this).parent().attr('id');
                var ndt = 1;         
                var ndd = 1;
                $(this).children('dt').each(function() {
                  $(this).attr('target', aid+'.'+ndt);
                  $(this).addClass('_read');
                  $(this).addClass('_subx');
                  ndt++;
                });
                $(this).children('dd').each(function() {
                  $(this).attr('id', aid+'.'+ndd);
                  $(this).addClass('_chapter');
                  $(this).slideUp();
                  ndd++;
                });
              });
            });
          }
          subit();
        break;
      }
      $(use).find('.open').each(function() {
        var tto = '#'+$(this).attr('target');
        $(tto).slideDown();
      });
      $(use).find('._read').each(function() {
        $(this).click(function() {
          if($(this).hasClass('_subx') == true) {
            $(this).siblings('._chapter').slideUp(300);
            var ost = $(this).attr('id');
            $(this).next(ost).slideDown(300);
          } else {
            $(use).find('._chapter').slideUp(300);
            var ot = $(this).attr('target');
            $(use).find('#'+ot).slideDown(300);
          }
        });
      });
    }
    
    // app menu
    if($(this).hasClass('x_ams') == true) {
			$('head').append('<link href="http://creath.de/xsrc/geq/app.css" type="text/css" rel="stylesheet" />');     
			$(to).append('<div id="window"></div>');
				$('#window').hide();
				$('#window').append('<div id="winbar"><span id="thistitle"></span></div>');
					$('#winbar').append('<input id="close" type="button" value="X" />');
					//$('#window').append('<div id="winmenu"></div>');
				$('#window').append('<iframe id="wincnt"></iframe>');
			$(to).append('<div id="appbar"></div>');
			var appc = 1;
			$(use).children('li').children('a').each(function() {
				var url = $(this).attr('href');                                 
				var txt = $(this).text();
				$('#appbar').append('<div class="app" id="app'+appc+'"></div>');
				$('#app'+appc).append('<div class="appicon" title="'+txt+'"></div>');
				$('#app'+appc).append('<div class="apptitle">'+txt+'</div>');
				$('#app'+appc).append('<input class="page" type="hidden" value="'+url+'" />');
				//$('#app'+appc).append('<div class="sub"></div>');
				$(this).next('ul').appendTo('#app'+appc+' .sub')
				
				$('#app'+appc+' .sub').hide();   
				appc++;
			});
			$('.app').each(function() {
				$(this).click(function() {
					var t = $(this).find('.apptitle').text();
					var page = $(this).find('.page').val();
					//var subm = $(this).find('.sub').html();
					$('#thistitle').text(t);
					$('#wincnt').attr('src', page);
					$('#window').fadeIn(300);
					//$('#winmenu').html(subm);
					//$('#winmenu').children('ul').show();
				});
			});
			$('.app').hover(function() {
				$(this).addClass('hover');
			}, function() {
				$(this).removeClass('hover');
			});
			$('#winbar').mousedown(function() {
				$('#window').draggable();
			});
			$('#close').click(function() {
				$('#window').fadeOut(300);
				$('#thistitle').text('');
				$('#wincnt').attr('src', '');
			});
			$(use).remove();
		}
  $(this).remove();
  });
});

