//
// create closure
//
(function($) {

  //
  // plugin definition: wakMask
  //
  $.fn.wakMask = function(options)
  {
  	// build main options before element iteration
  	var opts = $.extend({}, $.fn.wakMask.defaults, options);
    var elmLayer = $('#'+opts.layerId);
    var elmLayerMessage = $('#'+opts.layerMessageId);
    var elmLayerReferenceHeight = $('#'+opts.layerHeightReferenceId);
    var active = 0;
		var ie6SelectBoxes = [];
		
    // show
    function show(cb)
    {
			ie6SelectBoxes = [];
			if (jQuery.browser.msie) {
				$('#ifrmIBE').contents().find('select').each(function(){

				    if($(this).is(':visible'))
				    {
								ie6SelectBoxes[ie6SelectBoxes.length] = $(this);
								$(this).hide();
				    };

				});
			};
			
      $('html, body').animate({scrollTop:0},1); 
      elmLayer.height(elmLayerReferenceHeight.height()+opts.heightMargin);
      elmLayer.css({display: 'block', '-moz-opacity': '0.0', 'opacity': '0.00', 'filter': 'alpha(opacity=0)'});
      elmLayer.fadeTo(opts.fadeToSpeed, opts.fadeToOpacity, function()
      { 
        if(cb) 
        { 
          cb();
        }
        else
        {
          elmLayerMessage.show(); 
        }
      });
    };

    // hide
    function hide(cb)
    {
			if (jQuery.browser.msie) {
				for (var i=0; i<ie6SelectBoxes.length;i++)
				{
					ie6SelectBoxes[i].show();
				}
			};

      elmLayer.height(elmLayerReferenceHeight.height()+opts.heightMargin);
      elmLayer.fadeOut(opts.fadeToSpeed, null, function(){ elmLayer.hide(); });
      elmLayerMessage.fadeOut(opts.fadeToSpeed);
      if (cb) 
      { 
        cb();
      }
    };

    // show
    function showMessage()
    {
      elmLayerMessage.show();
    };

    // hide
    function hideMessage()
    {
      elmLayerMessage.hide();
    };

   	// iterate and reformat each matched element
  	return this.each(function() {
  	  $this = $(this);

      // make methods accessible
      $.extend(true, this, {
        show: show
      });
      $.extend(true, this, {
        hide: hide
      });
      $.extend(true, this, {
        showMessage: showMessage
      });
      $.extend(true, this, {
        hideMessage: hideMessage
      });

    });
  };

  //
  // plugin defaults: wakMask
  //
  $.fn.wakMask.defaults = 
  {
    layerId: 'tlhld_mask',
    layerMessageId: 'tlhld_mask_message',
    layerHeightReferenceId: 'page',
    heightMargin: -100,
    fadeToSpeed: 500,
    fadeOutSpeed: 500,
    fadeToOpacity: 0.90
  };

//
// end of closure
//
})(jQuery);


function wak_ibeFormular(params)
{
  $('#tlhld_mask')[0].show( function() { 

    if (typeof(document.formular_request_loaded)=='undefined' || document.formular_request_loaded == null)
    {
      $('#tlhld_formular_request_content').html('');
      $('#tlhld_formular_request_content').load('/site.ibe/ibe.v5.0.bookingformular.php', function(){
        $('#tlhld_formular_request_content').height(720);  
        $('#tlhld_formular_request').show();
      });      
    }
    else
    {
      $('#tlhld_formular_request').show();
      formular_request_init();
    }

  });  
};

function wak_ibeInit(params)
{
	// step 4
	// hide 'zurück' from otherwise list of hotels will shown
	$('#ifrmIBE').contents().find('table.botnav tr:eq(0)').find('td:eq(1)').hide();

	// hide ugly placeholder picture from search mask
	$('#ifrmIBE').contents().find('table.for4quicktab1 tr:eq(0)').find('td:eq(0)').remove();
	$('#ifrmIBE').contents().find('table.for4quicktab1 tr:eq(0)').find('td:eq(0)').addClass('tertab1td');
	$('#ifrmIBE').contents().find('table.for4quicktab2 tr:eq(0)').find('td:eq(0)').find('img').remove();
	$('#ifrmIBE').contents().find('table.for4quicktab2 tr:eq(0)').find('td:eq(0)').width(10);
	
	// show form because per css it is hidden
	$('#ifrmIBE').contents().find('form').hide();
	$('#ifrmIBE').contents().find('form').show();

	// resize iframe
	$('#ifrmIBE').show();
	var h = $('#ifrmIBE').contents().find('form').height();
	$('#ifrmIBE').height(h+50);
}
function wak_ibeOpen(params)
{
	$('#hotelInfo').hide();
	$('#hotelIBE').show();	

	var h = $('#ifrmIBE').contents().find('form').height();
	$('#ifrmIBE').height(h+50);
};

function wak_closeHTML(){
  if (typeof(popup) != 'undefined' && !popup.closed) {popup.close()};
};

function wak_openHTML(params) {
	var url 		 = params.url;
	var width 	 = params.width  || 500;
	var height 	 = params.height || 600;
  var features = arguments[3] || 'resizable=no,scrollbars=no,height='+height+',width='+width+',titlebar=0,left=0,top=0';
	var name     = arguments[4] || 'winPopup';
	
  window.onunload=wak_closeHTML;

  if (typeof(popup) != 'undefined' && !popup.closed) {popup.close()};
  popup=window.open(url,name || 'popup',features);
  popup.focus();
};

function wak_openPDF(params) {
	if (!params.id) { return false; }
	
	params.type = params.type || 'hotelinformation';
	wak_openHTML({
		url: 			'/site.services/pdf.php?type='+params.type+'&id='+params.id,
		width: 		params.width,
		height: 	params.height,
		features: params.features,
		name: 		params.name 
	});
};

$(document).ready(function(){

  $('#tlhld_mask').wakMask();
  $('#tlhld_mask').height($('#page').height());

	$('ifrmIBE') 
    .live('onload', function(event) { 
			wak_ibeInit();
  }); 

  $().bind('wak_ibeOpen', 		function (event, params) { wak_ibeOpen(params); });
  $().bind('wak_ibeFormular', function (event, params) { wak_ibeFormular(params); });
  $().bind('wak_openPDF', 		function (event, params) { wak_openPDF(params);	  	});

});