
FloatBanner = null;

function TFloatBanner(){
	this.bannerFloatStop = false;
	this.deltax = 170;
	this.deltay = 90;

	this.sites = [];
	//this.sites[0] = ['/banners/super_cena_500x300.swf', null, 500, 300, false];
	this.sites[0] = ['/banners/great_sale.jpg', 'http://eurotop.com.ua/ru/news/19.html', 240, 340, false];

	if(this.sites.length == 0) return;
	this.sitebanner = this.sites[Math.round(Math.random() * (this.sites.length - 1))];

	this.width = this.sitebanner[2] || 240;
	this.height = this.sitebanner[3] || 340;
	this.moving = this.sitebanner[4] || false;

	this.init = function(){
		var close_btn = new Element('a', {'class': 'banner_close_button'}).setStyle({cursor: 'pointer'}).update('закрыть');

		if(this.sitebanner[1] === null){
			var float_ban = new SWFObject(this.sitebanner[0], "fbanner", this.width, this.height, "8", "#FFFFFF");
			float_ban.addParam("wmode", "transparent");
			float_ban.write("bloatbanner");
		}
		else{
			var float_banner = new Element('img', {src: this.sitebanner[0], width: this.width, height: this.height}).setStyle({cursor: 'pointer'});
			float_banner.observe('click', this.close.bindAsEventListener(this));
			$('bloatbanner').insert({bottom: float_banner});
		}

		close_btn.observe('click', this.stop.bindAsEventListener(this));
		$('bloatbanner').insert({top: close_btn});

		this.go();
	}

	this.go = function(){
		var left = parseInt((document.viewport.getWidth() - this.width) / 2);
		var top = parseInt((document.viewport.getHeight() - this.height) / 2);

		$('bloatbanner').setStyle({position: 'absolute', left: left + 'px', top: top + 'px'});
		if(this.moving) this.float();
	}

	this.float = function(x){
		if(this.bannerFloatStop == false){
			x = x || 180;

			var left = parseInt((document.viewport.getWidth() - 240) / 2 + (Math.cos((Math.PI * x) / 180) * this.deltax));
			var top = parseInt((document.viewport.getHeight() - 320 - 100) / 2 + (Math.sin((Math.PI * x) / 180) * this.deltay));
			$('bloatbanner').setStyle({left: left + 'px', top: top + 'px'});
	
			this.float.bind(this).delay(.04, x + 1);
		}
	}

	this.stop = function(){
		this.bannerFloatStop = true;
		$('bloatbanner').remove();
	}

	this.close = function(){
		if(this.sitebanner[1].length)
			window.location = this.sitebanner[1];
		else
			$('bloatbanner').remove();
	}

	var loc = document.location.toString();
	if(loc.match(/.+(\/ru\/?|\/ua\/?)$/i) || loc.match(/http:\/\/(www\.)?eurotop.com.ua\/?$/i) || loc.match(/http:\/\/(www\.)?eurotop.ua\/?$/i)){
		this.init();
	}
	else{
		$('bloatbanner').remove();
	}
}

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

var collages = [new Element('img', {'src': '/images/girl_collage.jpg'}), new Element('img', {'src': '/images/man_collage.jpg'})];
$(document).observe("dom:loaded", function(){
	if($('collage') != null){
		var collage = collages[Math.round(Math.random() * (collages.length - 1))].setStyle({width: '344px', height: '360px'});
		$('collage').insert({top: collage});
	}
});

Event.observe(window, 'load', function(e){
	$$('img[rel="hover"]').each(function(el, i){
	    if (el.tagName.match(/img/i) && el.src != '') {   
	        defsrc = el.src;   
			hovsrc = el.src.substring(0, el.src.length - 4) + 'a' + el.src.substring(el.src.length - 4);
	        (function(defsrc, hovsrc) {   
	            el.onmouseover = function(){
	                if (this.src == defsrc) this.src = hovsrc;
	            }   
	            el.onmouseout = function(){   
	                if (this.src == hovsrc) this.src = defsrc;
	            }   
	        })(defsrc, hovsrc);   
	    }   
	});
});

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;
}

