function addBookmark(url, title)
{
  if (!url) url = location.href;
  if (!title) title = document.title;

  //Gecko
  if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) window.sidebar.addPanel (title, url, "");
  //IE4+
  else if (typeof window.external == "object") window.external.AddFavorite(url, title);
  //Opera7+
  else if (window.opera && document.createElement)
  {
    var a = document.createElement('A');
    if (!a) return false; //IF Opera 6
    a.setAttribute('rel','sidebar');
    a.setAttribute('href',url);
    a.setAttribute('title',title);
    a.click();
  }
  else return false;

  return true;
}

$(document).ready(function () {
	$.datepick.setDefaults({
		firstDay: 1,
		showStatus: false,
		navigationAsDateFormat: true,
		prevText: '< M',
		currentText: 'M yy',
		nextText: 'M >',
		closeAtTop: false,
		changeMonth: false,
		changeYear: false,
		dateFormat: 'yy-mm-dd'
	});

	$('#header .search input.query').focus(function () {
	        if ( $(this).val ( ) == $(this).attr('title') )
	        {
			$(this).val ( '' );
		}//if
	}).blur(function () {
	        if ( !$(this).val ( ) )
	        {
			$(this).val ( $(this).attr('title') );
		}//if
	});

	$('#header .search a').click(function ( ) {
		$(this).parent().submit();
	});

	$('#date').datepick();
	$('#feedback [name=date]').datepick();

	$('#header .booking a').click(function () {
		if ( $('#datepick-div:visible').length )
		{
			$('#date').datepick('hide');
		}//if
		else
		{
			$('#date').datepick('show');
		}//else
	});

	$('#header .top-info .buttons a[href=#bookmark]').click ( function ( ) {
		addBookmark ( window.location, document.title );
		return false;
	} );

	$('#content img[title]').each ( function ( ) {
		var img = $(this);

		if ( $.trim ( img.attr ( 'title' ) ) && img.width ( ) == 118 )
		{
			if ( img.parent ( 'a' ).length )
			{
				var repl = "<div class=\"simple-block\"><div class=\"image\"><a href=\""+ img.parent ( 'a' ).attr ( 'href' ) +"\" title=\""+ img.attr ( 'title' ) +"\"><img src=\""+ img.attr ( 'src' ) +"\" title=\""+ img.attr ( 'title' ) +"\" /></a></div><div class=\"text\">"+ img.attr ( 'title' ) +"</div></div>";
				img.parent ( 'a' ).replaceWith ( repl );
			}//if
			else
			{
				var repl = "<div class=\"simple-block\"><div class=\"image\"><img src=\""+ img.attr ( 'src' ) +"\" title=\""+ img.attr ( 'title' ) +"\" /></div><div class=\"text\">"+ img.attr ( 'title' ) +"</div></div>";
				img.replaceWith ( repl );
			}//else
		}//if
	} );
	
	$('#content p div:first-child').each ( function ( ) {
		$(this).parent ( ).replaceWith ( $(this).parent ( ).html ( ) );
	} );
	
	$('#content div.simple-block').prev ( '#content :not(#content div.simple-block)' ).after ( '<div class="clear"></div>' );
	$('#content div.simple-block').next ( '#content :not(#content div.simple-block)' ).before ( '<div class="clear"></div>' );

	var _print = $('#header .print' );
	_print.html ( _print.html ( ).replace ( '<!--', '' ).replace ( '-->', '' ) );

	/*
	$('#header .print a').click ( function ( ) {
		print ( );
	} );
	*/
	
	$('#content a[href$=.jpg], #content a[rel^=gallery-]').colorbox ( );

});
