window.addEvent('domready', function() {


	if ($$('a')) {
		$$('a').addEvents({
			'focus' : function(e){
				this.blur();
			}
		});
	}

	if ($$('object') && navigator.appName != 'Microsoft Internet Explorer') {
		$$('object').addEvents({
			'focus' : function(e){
				this.blur();
			}
		});
	}

	if ($$('a.actionOffer')) {
		$$('a.actionOffer').addEvent('click', function(e){
			var image = this.getChildren('img');
			var noprint = this.getProperty('rev') == 'noprint' ? '&noprint=true' : '';
			window.open('/ajax.php?show=actionOffer&type='+this.getProperty('rel')+noprint, '', 'width=300,height=200,scrollbars=yes');
			e.stop();
		});
	}

	if ($('mapEnlarge')) {
		$('mapEnlarge').addEvent('click', function(e) {
			window.open(this.href, '', 'width=750,height=690');
			e.stop();
		});
	}

	if ($('author')) {
		$('author').addEvents({
			'focus' : function(e) {
				if (this.value == 'Jméno' || this.value == 'Name' || this.value == 'Имя') {
					this.value = '';
				}
			},
			'blur' : function(e) {
				var lang = $$('head').getFirst('meta').getProperty('content');
				if (this.value == '' && lang == 'cs') {
					this.value = 'Jméno';
				}
				if (this.value == '' && lang == 'en') {
					this.value = 'Name';
				}
				if (this.value == '' && lang == 'ru') {
					this.value = 'Имя';
				}
				if (this.value == '' && lang == 'de') {
					this.value = 'Name';
				}
			}
		});
	}

	if ($('messageText')) {
		$('messageText').addEvents({
			'focus' : function(e) {
				if (this.value == 'Your message' || this.value == 'Vaše zpráva' || this.value == 'Ihre Nachricht' || this.value == 'Ваше сообщение') {
					this.value = '';
				}
			},
			'blur' : function(e) {
				var lang = $$('head').getFirst('meta').getProperty('content');
				if (this.value == '' && lang == 'cs') {
					this.value = 'Vaše zpráva';
				}
				if (this.value == '' && lang == 'en') {
					this.value = 'Your message';
				}
				if (this.value == '' && lang == 'ru') {
					this.value = 'Ваше сообщение';
				}
				if (this.value == '' && lang == 'de') {
					this.value = 'Ihre Nachricht';
				}
			}
		});
	}

	if ($('message')) {
		$('message').addEvents({
			'submit' : function(e) {
				var name = $('author').getProperty('value');
				var text = $('messageText').getProperty('value');

				if (name == 'Jméno' || name == 'Name' || name == 'Имя') {
					$('author').setStyle('border', '1px solid #FFFFFF');
					e.stop();
				} else {
					$('author').removeProperty('style');
				}
				if (text == 'Your message' || text == 'Vaše zpráva' || text == 'Ihre Nachricht' || text == 'Ваше сообщение') {
					$('messageText').setStyle('border', '1px solid #FFFFFF');
					e.stop();
				} else {
					$('messageText').removeProperty('style');
				}
				$('antispam').setProperty('value', (antiSpamValues[1] + antiSpamValues[2]));
			}
		});
	}

	if ($('submit')) {
		$('submit').addEvents({
			'click' : function(e) {
				e.stop();
				$('message').fireEvent('submit').submit();
			}
		});
	}

    if ($$(".boy")) {
        var loadingAnimation = new Image();
        loadingAnimation.src = '/public/images/loader.gif';
        $$(".boy").addEvent("click", function(e) {
        	if (process == true) {
        		return;
        	}
        	process = true;
        	$$('.boy').removeClass('selected');
        	this.addClass('selected');
        	var dataFile = this.getChildren('a').getProperty('rel');
        	var lang = $$('head').getFirst('meta').getProperty('content');
        	loadBoyDetail(lang, dataFile, loadingAnimation);
        	e.stop();
        });
    }

});


var loadBoyDetail = function(lang, dataFile, loadingAnimation) {
    var imageContainer = $('boyImage');
    imageContainer.set('html', '');
    imageContainer.setStyle('background-position', 'center');
    imageContainer.setStyle('background-image', 'url('+loadingAnimation.src+')');
    clearData();
    var ajax = new Request.JSON({
		url: '/ajax.php?lang='+lang+'&file='+dataFile,
		onFailure: function(e) {
			alert('Chyba');
		},
		onSuccess: function (jsonObj) {
			if (navigator.appName == 'Microsoft Internet Explorer') {
				imageContainer.setStyle('background-position', 'center top');
				imageContainer.setStyle('background-image', 'url('+'/public/data/boys/images/'+jsonObj.image+')');
				setData(jsonObj);
				process = false;
				return;
			}
			var detailImage = new Image;
			detailImage.addEvent('load', function(e){
				detailImage.removeEvents();
				// rozmery
				detailImage.inject(imageContainer);
				imageContainer.setStyle('background-image', '');
				setData(jsonObj);
				process = false;
			});
			detailImage.src = '/public/data/boys/images/'+jsonObj.image;
		}
	}).get();
};

var clearData = function() {
	$$('.name').set('html', '');
	$$('.age').set('html', '');
	$$('.hobbies').set('html', '');
	$$('.aboutMe').set('html', '');
	$$('.profession').set('html', '');
};

var setData = function(jsonObj) {
	$$('.name').set('html', jsonObj.name);
	$$('.age').set('html', jsonObj.age);
	$$('.hobbies').set('html', jsonObj.hobbies);
	$$('.aboutMe').set('html', jsonObj.aboutMe);
	$$('.profession').set('html', jsonObj.profession);
};
 {
	$$('.name').set('html', jsonObj.name);
	$$('.age').set('html', jsonObj.age);
	$$('.hobbies').set('html', jsonObj.hobbies);
	$$('.aboutMe').set('html', jsonObj.aboutMe);
	$$('.profession').set('html', jsonObj.profession);
};
