/**
 * Main entry point
 */
var domready = false;
window.addEvent('domready', function() {
	
	// Fade all menu item backgrounds
	$$('#leftmenu ul a:not(.selected)').addEvents({
		'mouseenter': function() {
			if (this.getElementsByTagName('img').length > 0) return false;
			this.set('morph', {duration: 100});
			this.morph({
				'background-color': '#cae7c8',
				'color': '#4b7448'
			});
		},
		'mouseleave': function() {
			if (this.getElementsByTagName('img').length > 0) return false;
			this.set('morph', {duration: 750});
			this.morph({
				'background-color': '#71a86e',
				'color': '#fff'
			});
		}
	});
	
	// Fade image links and searchbutton out on hover
	$$('#right1 a img, #leftmenu a img, #c a img, .searchbtn').addEvents({
		'mouseenter': function() {
			this.set('tween', {duration: 500});
			this.tween('opacity', '0.5');
		},
		'mouseleave': function() {
			this.set('tween', {duration: 500});
			this.tween('opacity', '1');
		}
	});
	
	// Searchbox focus handling
	$('searchbox').addEvents({
		'focus': function() {
			if (this.value == this.defaultValue) {
				this.value = '';
				this.setStyle('color', '#000');
			}
		},
		'blur': function() {
			if (this.value == '') {
				this.value = this.defaultValue;
				this.setStyle('color', null);
			}
		}
	});
	
	// Morph inpbut-buttons
	$$('.inpbtn').addEvents({
		'mouseenter': function() {
			this.set('morph', {duration: 500});
			this.morph({
				'background-color': '#cae7c8',
				'border-color': '#71a86e',
				'color': '#000'
			});
		},
		'mouseleave': function() {
			this.set('morph', {duration: 500});
			this.morph({
				'background-color': '#71a86e',
				'border-color': '#cae7c8',
				'color': '#fff'
			});
		}
	});
	
	domready = true;
});


// Send-to-friend
var stf = {
	show: function() {
		if (!domready) { alert('Vent til siden er indlęst.'); return; };
		try { $$('embed, object').setStyle('visibility', 'hidden'); } catch (e) {}
		var ws = window.getScrollSize();
		$('bigbg').setStyle('height', ws.y+'px');
		$('bigbg').fade('hide').setStyle('display', 'block').fade(0.8);
		ws = window.getScroll();
		$('sendtofriend').setStyle('top', (ws.y+100)+'px');
		$('sendtofriend').fade('hide').setStyle('display', 'block').fade(1);
	},
	cancel: function() {
		$('bigbg').fade(0);
		$('sendtofriend').fade(0);
		setTimeout(function() {
			$$('embed, object').setStyle('visibility', 'visible');
		}, 500);
	}
};