<!--

function FlashWindow(src, w, h){
	this.src = '/flash/' + src;
	this.w = w;
	this.h = h + 20;

	this.className = 'flash_window';
	this.closeButton = '<div class="close_button">закрити</div>';
	this.flashTag = new Template('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="#{width}" height="#{height}"><param name="movie" value="#{src}"><param name="quality" value="high"><embed src="#{src}" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="#{width}" height="#{height}"></embed></object>');

	this.ptr = null;

	this.draw_window = function(){
		this.ptr = document.createElement('div');

		var dW = document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth;
		var dH = document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;

		$(this.ptr).addClassName(this.className);
        $(this.ptr).setStyle({
			width: this.w + 'px',
			height: this.h + 'px',
			left: parseInt((dW - this.w) / 2) +  'px',
			top: (parseInt((dH - this.h) / 2) + document.documentElement.scrollTop) + 'px'
		});

		new Insertion.Top($$('body')[0], $(this.ptr))
		new Insertion.Bottom($(this.ptr), '<p align="center" style="margin-top: 100px;"><img src="/images/loading_16x16.gif" width="16" height="16"></p>')

		new Insertion.Top($(this.ptr), this.closeButton)
		var closeButton = $(this.ptr).getElementsBySelector('div')[0];
		closeButton.observe('mouseover', function(e){
			Event.element(e).addClassName('close_button_hover');
		});
		closeButton.observe('mouseout', function(e){
			Event.element(e).removeClassName('close_button_hover');
		});
		closeButton.observe('click', function(e){
			Event.element(e).up().remove();
		});
	}

	this.insert_flash = function(){
		var object = this.flashTag.evaluate({src: this.src, width: this.w, height: this.h - 20});
		Insertion.Bottom.delay(2, this.ptr, object);
		Element.remove.delay(2, $(this.ptr).getElementsBySelector('p')[0]);
	}

	this.execute = function(){
		this.draw_window();
		new Element.hide($(this.ptr));
		this.insert_flash();
		new Effect.Appear($(this.ptr));

		return false;
	}

	return this.execute();
}

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

function client_frame(){
	var frame = '<div id="client_frame"></div>';
	var elements = $$('body')[0].getElementsByClassName('client_frame');

	for(var i = 0; i < elements.length; i++){
		$(elements[i]).observe('mouseover', function(e){
			new Insertion.Top(Event.element(e).parentNode, frame);
			//$('client_frame').clonePosition(Event.element(e));
			$('client_frame').observe('mouseout', function(e){
				Event.element(e).remove();
			});
		});
	}
}

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

function onload_function(){
	set_light_on();
	swap_images_run();
	set_effects();
}

function set_light_on(){
	if(typeof LIGHT_ON === undefined || LIGHT_ON.length == 0)
		return;

	var images = $$('body')[0].getElementsByClassName('swap_image');
	for(var i = 0; i < images.length; i++){
		for(var j = 0; j < LIGHT_ON.length; j++){
			if ($(images[i]).src.match(LIGHT_ON[j])){
				//$(images[i]).removeClassName('swap_image');
				$(images[i]).src = images[i].src.substring(0, images[i].src.length - 4) + 'a' + images[i].src.substring(images[i].src.length - 4);
			}
		}
	}
}

function swap_images_run(){
	var images = $$('body')[0].getElementsByClassName('swap_image');
	for (var i = 0; i < images.length; i++){
		$(images[i]).observe('mouseover', function(e){
			var img = Event.element(e);
			if(img.src){
				img.writeAttribute('swap_src', img.src);
				img.src = img.src.substring(0, img.src.length - 4) + 'a' + img.src.substring(img.src.length - 4);
			}
		});
		$(images[i]).observe('mouseout', function(e){
			var img = Event.element(e);
			if(img.readAttribute('swap_src')){
				img.src = img.readAttribute('swap_src');
				img.writeAttribute('swap_src');
			}
		});
	}
}

function set_effects(){
	if(typeof Effect === undefined)
		return;

	var elements = $$('body')[0].getElementsByClassName('effect');
	for(var i = 0; i < elements.length; i++){
		$(elements[i]).observe('click', function(e){
			var el = Event.element(e);
			eval('new Effect.' + el.readAttribute('rel')/*.capitalize()*/ + '(el)');
			Effect.Appear.delay(2.5, el);
		});
	}
}

//-->
