
function cBrowser() {
	var ua = navigator.userAgent;
	var bName = function () {
		if (ua.search(/MSIE/) > -1) return "ie";
		}();
		
	var version = function (bName) {
		switch (bName) {
			case "ie" : return (ua.split("MSIE ")[1]).split(";")[0];break;
	}}(bName);
	return [bName];
}
function loadScript_K5M(url, callback,id_script)
{
	
		// adding the script tag to the head as suggested before
		var head = document.getElementsByTagName('head')[0];
		var script = document.createElement('script');
		script.type = 'text/javascript';
		script.src = url;
		script.id = id_script;
		
		if(cBrowser()=='ie'){
			setTimeout(callback, 300);
		}else{
			script.onreadystatechange = callback;
			script.onload = callback;
		
		}
		head.appendChild(script);
}

loadScript_K5M('http://advertising.tech.mos.ru//bitrix/templates/.default/static/js/postmessage.js',init_event_banner_K5M,'script_postmessage');


function init_event_banner_K5M(){

	pm.bind("resaiz_frame_banner_K5M", function(data) {
			if(data['param_h']>0){
				var frameElement = document.getElementById('banner_frame_K5M'); 
				frameElement.style.height = data['param_h'] + 'px'; 
				var frameElement = document.getElementById('banner_block_K5M'); 
				frameElement.style.height = data['param_h'] + 'px'; 
			}
			
			if(data['param_w']>0){
				var frameElement = document.getElementById('banner_frame_K5M'); 
				frameElement.style.width = data['param_w'] + 'px'; 
				var frameElement = document.getElementById('banner_block_K5M'); 
				frameElement.style.width = data['param_w'] + 'px'; 
			}
			return data;
	}); 

	pm.bind("add_new_from_K5M", function(data){
		var el = document.createElement("iframe");
		
		el.id = 'iframe_';
		el.src = data['param_url']+'&rand_id=K5M';
		el.style.top = '0';
		el.style.left = '0';
		el.style.width = '100%';
		el.style.height = $(window).height()+'px';
		el.style.border = 'medium none';
		el.style.zIndex = 9999;
		el.style.overflow = 'hidden';
		el.style.position = 'fixed';
		el.style.backgroundColor = 'transparent';
		document.body.appendChild(el);
	});

	pm.bind('remove_adver_frame_K5M', function(){
		document.body.removeChild(document.getElementById("iframe_"));
	});
}


document.write('<div style="display: inline-block; height: 400px; width: 240px;" id="banner_block_K5M"><iframe style="height: 400px; width: 240px; border: none; z-index: 1; overflow: hidden; position: absolute; background-color:transparent" scrolling="no" frameborder="0" allowtransparency="true"  name="banner_frame_K5M" id="banner_frame_K5M" src="http://advertising.tech.mos.ru/banner.php?site_id=vo&rand_id=K5M&type=left_banners_2&ref_url='+encodeURIComponent(document.location.href)+'"></iframe></div>');
