<!--

function drawCollage(s, m, l){
	var images = null, w = null, h = null, src = null;

	if(m == 1){
		images = ['main_girl.jpg', 'main_man.jpg', 'main_woman.jpg'];
		w = 390;
		h = 630;
	}
	else{
		images = ['girl.jpg', 'man.jpg', 'woman.jpg'];
		w = 311;
		h = 527;
	}

	if(s == 1){
		src = '/collages/' + images[Math.round(Math.random() * (images.length - 1))];
	}
	else{
		src = '/collages/kz/' + images[Math.round(Math.random() * (images.length - 1))];
	}


	if(m == 1)
		document.write('<img src="' + src + '" width="' + w + '" height="' + h + '">');
	else
		document.write('<a href="/' + l + '"><img src="' + src + '" width="' + w + '" height="' + h + '"></a>');
}

function scrollerClass(container, buttons, options){
	this.container	= $(container);
	this.btn_left	= $(buttons[0]);
	this.bnt_right	= $(buttons[1]);

	this.content = null;
	this.listener = null;
	this.timer = null;
	
	this.container_width = 0;
	this.content_width = 0;
	this.position = 0;

	this.options = Object.extend({
		offset: 5, delay: 100
	}, options);

	this.init = function(){
		this.content = this.container.down('div.scrollContent');
		this.listener = this.action.bindAsEventListener(this);

		$A([this.btn_left, this.bnt_right]).each(function(btn){
			Event.observe(btn, 'mouseover', this.listener);
			Event.observe(btn, 'mouseout', this.listener);
		}.bind(this));

		this.reset();
	};

	this.reset = function(){
		this.container_width = this.container.getDimensions().width;
		this.content_width = this.content.firstDescendant().getDimensions().width;
		this.position = 0;
		this.move();
	};

	this.action = function(e){
		var delta = e.element() === this.btn_left ? 1 : (e.element() === this.bnt_right ? -1 : 0);
		switch(e.type){
			case "mouseover":
			case "mousedown":
				if(this.container_width < this.content_width && delta != 0){
					this.scroll(delta);
					this.timer = setInterval(this.scroll.bind(this, Math.round(delta * this.options.offset)), this.options.delay);
				}
				break;
			case "mouseout":
			case "mouseup":
				clearInterval(this.timer)
				break;
		}
	};

	this.scroll = function(offset){
		if(offset < 0){ // right button (move left)
			this.position = Math.max(this.position + offset, this.container_width - this.content_width);
		}
		if(offset > 0){ // left button (move right)
			this.position = Math.min(this.position + offset, 0);
		}                                                                    

		this.move();
	};

	this.move = function(position){
		this.content.setStyle({marginLeft: this.position + 'px'});
	}

	Event.observe(window, 'load', this.init.bindAsEventListener(this));
	Event.observe(window, 'resize', this.reset.bindAsEventListener(this));
}

function newsImagesGallery(){
	var newsImagesLinks = $$('#newsImages a');
	newsImagesLinks.each(function(clickImage){
		clickImage.observe('click', function(e){
			e.stop();
			if(clickImage.href.blank()) return;
			var zoomImage = new Element('img').setStyle({'position': 'absolute', 'cursor': 'pointer'}).hide();
	        zoomImage.observe('load', function(e){
				$('newsImages').insert({'top': zoomImage});
				var sizeLink = clickImage.firstDescendant().getDimensions();
				var sizeCont = $('newsImages').getDimensions();
				var sizeZoom = zoomImage.getDimensions();

				var positionLink = clickImage.firstDescendant().positionedOffset();
				var positionCont = $('newsImages').positionedOffset();

				zoomImage.setStyle({'left': positionLink.left + 'px', 'top': positionLink.top + 'px'});

				new Effect.Parallel([
				    new Effect.Opacity(zoomImage, {
						sync: true,
						from: 0.25, to: 1.0
					}),
					new Effect.Move(zoomImage, {
						sync: true,
						x: positionCont.left,
						y: positionCont.top,
						mode: 'absolute'
					}),
					new Effect.Scale(zoomImage, 100, {
						sync: true,
						scaleMode: { originalWidth: sizeZoom.width, originalHeight: sizeZoom.height }
					})
				], {
					duration: 0.8,
					beforeStart: function(){
						zoomImage.setStyle({'width': sizeLink.width + 'px', 'height': sizeLink.height + 'px'});
						zoomImage.setStyle({'opacity': 0.25}).show();
	   				},
					afterFinish: function(){
						zoomImage.observe('click', function(e){
							new Effect.Parallel([
	   						    new Effect.Opacity(zoomImage, {
									sync: true,
									from: 1.0, to: 0.25
								}),
								new Effect.Move(zoomImage, {
									sync: true,
									x: positionLink.left,
									y: positionLink.top,
									mode: 'absolute'
								}),
								new Effect.Scale(zoomImage, 100, {
									sync: true,
									scaleMode: { originalWidth: sizeLink.width, originalHeight: sizeLink.height }
								})
							], {
								duration: 0.8,
								afterFinish: function(){
									zoomImage.remove();
								}
							});
						});
					}
				});
			});
			zoomImage.src = clickImage.href;
		});
	});

}

function CollectionFrame(){
	var self = this;
	var close_but = new Element('img', {id: 'close_button', src: '/images/close.gif', width: 16, height: 16}).setStyle({position: 'absolute', cursor: 'pointer', z_index: 100});

	this.open = function(lang){
		if(!$('collectionFrame').visible()){
			var frameSize = {marginLeft: ((document.viewport.getDimensions().width - 600) / 2) + 'px',
							 marginTop: ((document.viewport.getDimensions().height - 400) / 2) + 'px',
							 width: '600px',
							 height: '400px'}

			close_but.setStyle({marginTop: '4px', marginLeft: 580 + 'px'});

			new Ajax.Request("/?module=catalogue&action=collectionframe&lang=" + lang, {
				method: 'GET',
				parameters: 'AJAXMODE=1',
				onSuccess: function(transport){
					$('collectionFrame').firstDescendant().update(transport.responseText);
					$('collectionFrame').insert({top: close_but});
					$('close_button').observe('click', self.close);
				},
				onComplete: function(){
					$$('object').invoke('hide');
				    $('collectionFrame').setStyle(frameSize);
					new Effect.BlindDown('collectionFrame', {afterFinish: function(){
						Event.observe('collectionFrame', 'dblclick', self.close);
					}});
				}
			});
		}
		else{
			this.close();
		}
	};

	this.close = function(){
		$('close_button').stopObserving('click', self.close).remove();
		new Effect.BlindUp('collectionFrame', {afterFinish: function(){
			Event.stopObserving('collectionFrame', 'dblclick', self.close);
			$('collectionFrame').firstDescendant().update();
			$$('object').invoke('show');
		}});
	};
}

function newWindow(url, w, h){
	var x = parseInt((window.screen.width - w) / 2);
	var y = parseInt((window.screen.height - h - 50) / 2);

	window.open(url, "newWindow", "width=" + w + ", height=" + h + ", left=" + x + ", top=" + y + ", scrollbars=0");

	return false;
}

function changeLanguage(lang){
	var loc = document.location.toString();
	if(loc.match(/\/ru\/|\/ua\//i))
		var path = loc.replace(/\/ru\/|\/ua\//i, '/' + lang + '/');
	else
		var path = 'http://' + document.location.host + '/' + lang;

	document.location = path;
	return false;
}

//------------------------------------------------------------------------------

try{
	document.execCommand("BackgroundImageCache", false, true);
} catch(e) {}

Event.observe(document, 'dom:loaded', function(e){
	$$('input[rel="clear"]').each(function(el, i){
		if(el.type.match(/text/i) && !$F(el).blank()){
			var defValue = el.value;
			el.observe('focus', function(e, defValue){
				if(this.value == defValue) this.value = "";
			}.bindAsEventListener(el, defValue));
			el.observe('blur', function(e, defValue){
				if(this.value == "") this.value = defValue;
			}.bindAsEventListener(el, defValue));
		}
	});

	$$('img[rel~="hover"]').each(function(el, i){
		if (el.src.blank() == false) {   
			var defsrc = el.src;   
			var hovsrc = el.src.substring(0, el.src.length - 4) + '_a' + el.src.substring(el.src.length - 4);
			el.observe('mouseover', function(e, src){
				this.src = src;
			}.bindAsEventListener(el, hovsrc));
			el.observe('mouseout', function(e, src){
				this.src = src;
			}.bindAsEventListener(el, defsrc));
			new Element('img', {src: hovsrc});
		}   
	});

	$$('img[rel~="hbg"]').each(function(el, i){
		var defbg = el.up('td').style.backgroundImage;
		var hovbg = 'url(/menu/bg_menu.gif)';
		el.observe('mouseover', function(e, bg){
			this.up('td').setStyle({backgroundImage: bg});
		}.bindAsEventListener(el, hovbg));
		el.observe('mouseout', function(e, bg){
			this.up('td').setStyle({backgroundImage: bg});
		}.bindAsEventListener(el, defbg));
	});
	
	$$('img[rel="fade"]').each(function(el, i){
		el.setOpacity(0.6);
		(function(object, start, finish, ptr){
			object.observe('mouseover', function(e){
				if(ptr !== null) ptr.cancel();
				ptr = new Effect.Appear(object, {duration: 0.3, from: start, to: finish, afterFinish: function(){
					ptr = null;
				}});
			});
			object.observe('mouseout', function(e){
				if(ptr !== null) ptr.cancel();
				ptr = new Effect.Fade(object, {duration: 0.2, from: finish, to: start, afterFinish: function(){
					ptr = null;
				}});
			});
		})(el, 0.6, 1.0, null);
	});	
});

//-->