var $j = jQuery.noConflict();

$j(document).ready(function()
{
	/**
	 * Prices table
	 */
	$j('#prices tbody td.title').hover(
		function(){$j(this).find('div.hidden').show().css('top', $j('#body div.sidebar').position().top).css('left', $j('#body div.sidebar').position().left); /*blink animation*/$j(this).toggleClass('hover');setTimeout((function (e) { return function () { $j(e).removeClass('hover'); } })(this), 200);},
		function(){$j(this).find('div.hidden').hide();}
	);
	
	/**
	 * Map
	 */
	$j(document).ready(function(){
		$j("#map div.area").each(
			function(){
				$j(this).hover(function(){
					$j('<div class="bubble"></div>').css({left:20,top:20}).append($j(this).attr('content') + '<div class="clear"></div>').appendTo(this);
				}, function(){
					$j('#map div.bubble').remove();	
				});
			}
		);
	});
	
	/**
	 * Navigation effects
	 */
	$j("ul#navigation li").hover(
		function () {
			$j(this).toggleClass('hover');
			setTimeout((function (e) { return function () { $j(e).removeClass('hover'); } })(this), 200);
		},
		function () { }
	);
	
	/**
	 * Lightbox plugin
	 */
     /*
	$j("a[rel^='gallery']").slimbox({}, null, function(el){
		return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel));
	});
	*/
	/**
	 * Rounded plugin
	 */
	if(!$j.browser.msie){
		$j(".rounded").corner("round 8px");
	}
	
	/**
	 * Blinking animation
	 */
	setInterval("blinkAnimation()", 800);

    $j(function(){
    /**
    * Custom map function
    * var map holds information about positioned items in map
    */
    var map = [
    {x:355, y:45, image: '38634373.jpg', title: 'Gediminas Castle', description:'The red-bricked tower is preserved from the Higher Castle erected in the 13th-14th centuries. One may have a beautiful panoramic view to the Old town and the towers of churches, city centre and Neris river valleys from the sightseeing site on top of the tower.', css_class:''},
    {x:295, y:55, image: '68017844.jpg', title: 'The Cathedral Square', description:'The Cathedral Square is one of the first places in Vilnius to be mentioned in written sources. And up to the present it is the axis of the public and spiritual life of the city.', css_class:''},
    {x:305, y:145, image: '72652560.jpg', title: 'Pilies str.', description:'One of the oldest - just like all medieval towns, Vilnius was developing around the Town Hall and the central Pilies Street. Although Vilnius suffered many fires, this street preserved its authentic appearance and specimen of the old architecture: small yards, arcades, vaults, original stairways and basements.', css_class:''},
    {x:265, y:110, image: '81390979.jpg', title: 'Residence of President of the Republic of Lithuania', description:'', css_class:''},
    {x:285, y:210, image: '56963199.jpg', title: 'The City Hall Square', description:'Town Hall was the central point in the life of the whole city and the nearby square was the place of executions, marketplaces and public life. Now it is a place of public and entertainment events of Vilnius.', css_class:''},
    {x:305, y:285, image: '21134201.jpg', title: 'Gates of Dawn', description:'One of the main symbols of Vilnius. The picture of the Mother of Mercy of the Gates of Dawn is well known not only in the whole Lithuania, but also among Catholics worldwide.', css_class:''},
    {x:277, y:305, image: 'halesmarket.gif', title: 'The Hale Market', description:'The Hale Market is one of the two large food markets in Vilnius. It is one of the oldest market-places in Vilnius, built in 1906 and recently renovated.', css_class:''},
    {x:255, y:282, image: false, title: 'The bus\' stop "Aušra"', description:'The most popular markets such as "Akropolis" and "Europa" are easily reachable by public transport (microbus No2 - every 5 minutes)', css_class:''},
    {x:248, y:304, image: '72652562.jpg', title: 'Hotel style B&B Florens', description:'<strong>B&B Florens<\/strong> (Sodu str.4) is situated in the Old Town of Vilnius.', css_class:'bloom two'},
    {x:310, y:322, image: '72652561.jpg', title: 'Florens Boutique', description:'<strong>Florens Boutique<\/strong> (Aušros Vartu str.29) is situated in the Old Town of Vilnius.', css_class:'bloom one'},
    {x:245, y:365, image: 'trainstation.gif', title: 'The Train Station', description:'The Train Station with access to the ancient Lithuanian capital of Trakai as well as to Kaunas, Riga, Tallinn and other local/international destinations.', css_class:''},
    {x:294, y:330, image: false, title: 'Free of charge public Parking', description:'', css_class:'parking'},
    {x:257, y:330, image: 'parking.gif', title: 'The Guarded parking', description:'', css_class:'parking'},
    {x:205, y:345, image: 'busstation.gif', title: 'The Central Bus Station', description:'The Central Bus Station with access to the ancient Lithuanian capital of Trakai as well as to Kaunas, Riga, Tallinn and other local/international destinations.', css_class:''}
    ];

    /**
    * Append triggering icons
    */
    $j.each(map, function(key){
    $j('#map').append('<div id="map_' + key + '" class="area ' + this.css_class + '" style="top:' + this.y + 'px; left:' + this.x + 'px;"><\/div>');
    })

    /**
    * Trigger popup box
    */
    $j('#map div.area').hover(function(e) {
        var $o = map[this.id.substr(4)];
        // make sure to remove previous popup before creating new one
        $j('#map div.bubble').remove();
        // create popup box with the indicator
        if($o.css_class == 'bloom one' || $o.css_class == 'bloom two')
        {
            $j('#map').append('<div class="bubble" style="top:' + $o.y + 'px; left:' + $o.x + 'px;"><div class="indicator"><\/div> ' + ($o.image.length > 0 ? '<img src="http://www.guesthouse.lt/wp-content/themes/wp-theme/places/' + $o.image + '" alt="' + $o.title + '">' : '') + ($o.description.length > 0 ? '<p>' + $o.description + '<\/p>' : '') + '<div class="clear"><\/div><\/div>');
        }
        else
        {
            $j('#map').append('<div class="bubble" style="top:' + $o.y + 'px; left:' + $o.x + 'px;"><div class="indicator"><\/div> ' + ($o.image.length > 0 ? '<img src="http://www.guesthouse.lt/wp-content/themes/wp-theme/places/' + $o.image + '" alt="' + $o.title + '">' : '') + '<div class="title">' + $o.title + '<\/div>' + ($o.description.length > 0 ? '<p>' + $o.description + '<\/p>' : '') + '<div class="clear"><\/div><\/div>');
        }

        // remove popup box when bubble indicator is unhovered
        $j('#map div.indicator').hover(function(){}, function(){$j('#map div.bubble').remove();});
        }, function(){});

    $j('#map').hover(function(){$j('#map div.bubble').remove();}, function(){});
    });
    
});

function popup_box(e){
	$j('body').append('<div id="message_box">' + e + '</div>');
	$j('#message_box').css('left', ($j(window).width()/2)-$j('#message_box').width()/2).css('top', ($j(window).height()/2)-$j('#message_box').height()/2);
	
	$j(window).click(function(){$j('#message_box').remove();});
}

function blinkAnimation() 
{
  $j(".blink").animate(
  {
    opacity: 0
  }, "fast", "swing").animate(
  {
    opacity: 1
  }, "fast", "swing");
}

function clearText(field)
{
    if (field.defaultValue == field.value) field.value = '';
    else if (field.value == '') field.value = field.defaultValue;
}
