function show_help(in_URL, in_x, in_y, in_flash) {
  if (in_flash == 1) {
    in_URL = help_URL+in_URL;
  }
  var helpwindow = window.open(in_URL, 'helpbox', 'width=400,height=550,toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,dependent=yes');  
  helpwindow.focus();
}

function flash_block() {
  var stayguest_loading_message = "Bitte haben Sie einen Augenblick Geduld.<br />Die Vorschau wird erstellt ...";
  $.blockUI({ message: '<h1 class="loading">'+stayGuest_loading_message+'</h1>' });
}

$(document).ready(function() {
  /**
   * die Startwerte von focusEmpty Feldern ermitteln
  */	

  focusEmpty_Fields = Array();
  
  $('input.focusEmpty').each(function() {
  	focusEmpty_Fields[$(this).attr('name')] = $(this).val();
  });
  
  /**
   * onFocus/onBlur Event für focusEmpty Felder
  */
  $('input.focusEmpty').focus(function() 
  {
  	if ($(this).val() == focusEmpty_Fields[$(this).attr('name')]) {
  		$(this).val('');
		$(this).addClass('focusEmptyChanged');
  	}
  }).blur(function()
  {
  	if (($(this).val() == '') || ($(this).val() == focusEmpty_Fields[$(this).attr('name')])){
  	  $(this).val(focusEmpty_Fields[$(this).attr('name')]);
	  $(this).removeClass('focusEmptyChanged');
  	}
  });

  /* Bilder vorladen */
  var imgPreload = new Image();
  imgPreload.src = '/system/images/loading.gif';

  $('a.help').click(function(event) {
    /* Position ermitteln */
    var elm_x = event.pageX + 15;
    var elm_y = event.pageY;

    var ajaxURL = $(this).attr('href');

    show_help(ajaxURL, elm_x, elm_y);
    return false;
  });

  $('a.help_bullet').focus(function() {
    $(this).blur();
  });

  $('a.help_tooltip').click(function() {
    return false;
  });

  $('.help_tooltip').tooltip({
    delay: 0,
    showURL: false,
    track: true,
    extraClass: 'text_tip',
    bodyHandler: function() {
      var ajaxURL = $(this).attr('href');
      return $.ajax({
        url: ajaxURL,
        async: false
        }).responseText;
    }
  });


  $('.object_tooltip').tooltip({
    delay: 0,
    showURL: false,
    track: true,
    extraClass: 'text_tip',
    bodyHandler: function() {
      var ajaxURL = this.tooltipText;
      return $.ajax({
        url: ajaxURL,
        async: false
        }).responseText;
    }
  });

  $('.image_tooltip').tooltip({
    delay: 0,
    showURL: false,
    track: true,
    extraClass: 'image_tip',
    bodyHandler: function() {
      foo = this.tooltipText.split("|");
      result = '<img src="'+foo[0]+'" title="" />';
      result = "<h2>"+foo[1]+"</h2>"+result;
      return result;
    }
  });



  $('.text_tooltip').tooltip({
    delay: 0,
    showURL: false,
    track: true,
    extraClass: 'text_tip',
    bodyHandler: function() {
      return this.tooltipText;
    }
  });


  $('div.jpg_preview').hide();
  $('div.jpg_preview:first').show();

/*  var foo = $('div.jpg_preview:first img').css('height');
  $('div#preview_container').css('height', foo); */


  $('a.jpg_preview').click(function() {
    var foo = $(this).attr('href');
    $('div.tab_normal a.current').removeClass('current');
    $(this).addClass('current');
    $('div.jpg_preview').fadeOut('fast');
    $('div'+foo).fadeIn('fast');  
    $(this).blur();
    return false;
  });

  $('a.preview_next').click(function() {
    var foo = $('div.jpg_preview:visible').attr('id');
    foo = parseInt(foo.replace('preview_','')) + 1;

    if ($('div#preview_'+foo).size() == 1) {
      $('div.tab_normal a.current').removeClass('current');
      $('a.jpg_preview[href=#preview_'+foo+']').addClass('current');
      $('div.jpg_preview').fadeOut('fast');
      $('div#preview_'+foo).fadeIn('fast');  
    }
    $(this).blur();
    return false;
  });

  $('a.preview_prev').click(function() {
    var foo = $('div.jpg_preview:visible').attr('id');
    foo = parseInt(foo.replace('preview_','')) -1;
    if ($('div#preview_'+foo).size() == 1) {
      $('div.tab_normal a.current').removeClass('current');
      $('a.jpg_preview[href=#preview_'+foo+']').addClass('current');
      $('div.jpg_preview').fadeOut('fast');
      $('div#preview_'+foo).fadeIn('fast');  
    }
    $(this).blur();
    return false;
  });


  $('a.reload_captcha').click( function() {
    var foo = $('img#captcha_img').attr('src');
    foo = foo.split('?');
    $('img#captcha_img').attr('src', foo[0]+'?' + (new Date()).getTime());
    return false;
  });


  // Akkordion
  $('.accordion dt').mouseover(function() {
	$(this).css('cursor', 'pointer');
	$(this).addClass('hover');
  });

  $('.accordion dt').mouseout(function() {
	$(this).removeClass('hover');
  });


  $('.accordion dd').hide();
  $('.accordion dt').click(function() {
    $(this).next('dd').slideToggle('fast').siblings('dd').slideUp('fast');
    $(this).toggleClass('down');
  });
});

Shadowbox.init({
    language:   "de-DE",
    players:    ["flv"],
    overlayColor: "#fff"
});


