var banner = {
	cookie: "mts20100125",
	small: false,
	timer: 0,
	banners: {},

	init: function(cookie, banners) {
		this.cookie = cookie;
		this.banners = banners;
	},

	cookieExists: function() {
		if (document.cookie.indexOf(this.cookie) == -1)
			return false;
		else
			return true;
	},
	
	setCookie: function() {
		document.cookie = this.cookie + "=1;expires=" + new Date((new Date()).getTime() + 86400000) + ";path=/;";
	},
	
	setSmall: function(small) {
		this.small = small;
	},

	isSmall: function() {
		return this.small;
	},

	setTimer: function(timer) {
		this.timer = timer;
	},

	getTimer: function() {
		return this.timer;
	},

	showBanner: function(banner) {
		$(banner.placeholder).flash({
			"src": banner.src,
			"width": "100%",
			"height": banner.height,
			"quality": "high",
			"align": "middle",
			"play": "true",
			"loop": "true",
			"scale": "showall",
			"wmode": "opaque",
			"devicefont": "false",
			"bgcolor": "#d4d4d4",
			"menu": "true",
			"allowFullScreen": "false",
			"allowScriptAccess": "sameDomain",
			"salign": "",
			"access":"domain",
			"express":"express_install.swf",
			"classid":"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",
			"codebase":"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=",
			"plugin":"http://get.adobe.com/flashplayer",
			"mime":"application/x-shockwave-flash",
			"version":"9.0.24"
		});
	},

	showBig: function(show) {
		var banner = this.banners.big;
		this.showBanner(banner);
		if (!show) {
			$(banner.placeholder).hide();
		}
	},
	
	showSmall: function(show) {
		var banner = this.banners.small;
		this.showBanner(banner);
		if (!show)
			$(banner.placeholder).hide();
	}
}

var ph = {
	main: "#topline",
	big: "#topline-flash-big",
	small: "#topline-flash-small"
};

$(document).ready(function() {

	banner.init(
		"mts_banner", 
		{
			big: {
				placeholder: ph.big,
				src: "http://s.afn.by/images/ads/MTS_Business_100px150_5.swf",
				height: "150"
			}, 
			small: {
				placeholder: ph.small,
				src: "http://s.afn.by/images/ads/MTS_Business_100px60_5.swf",
				height: "60"
			}
		}
	);

	if (banner.cookieExists()) {
		banner.showSmall(true);
		banner.showBig(false);
		banner.setSmall(true);
		$(ph.main).live("mouseover", function() {
			if (banner.getTimer() != 0) {
				clearTimeout(banner.getTimer());
			}
			if (banner.isSmall()) {
				banner.setTimer(setTimeout('$(ph.small).toggle();$(ph.big).toggle();banner.setSmall(false);', 1000));
			}
		});
		$(ph.main).live("mouseout", function() {
			if (banner.getTimer() != 0) {
				clearTimeout(banner.getTimer());
			}
			if (!banner.isSmall()) {
				banner.setTimer(setTimeout('$(ph.big).toggle();$(ph.small).toggle();banner.setSmall(true);', 1000));
			}
		});
	}
	else {
		banner.showBig(true);
		banner.showSmall(false);
		banner.setSmall(false);
		banner.setCookie();
	}
});
