
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_ZWI(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_ZWI('http://advertising.tech.mos.ru//bitrix/templates/.default/static/js/postmessage.js',init_event_banner_ZWI,'script_postmessage');


function init_event_banner_ZWI(){

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

	pm.bind("add_new_from_ZWI", function(data){
		var el = document.createElement("iframe");
		
		el.id = 'iframe_';
		el.src = data['param_url']+'&rand_id=ZWI';
		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_ZWI', function(){
		document.body.removeChild(document.getElementById("iframe_"));
	});
}


document.write('<div style="display: inline-block; height: 400px; width: 240px;" id="banner_block_ZWI"><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_ZWI" id="banner_frame_ZWI" src="http://advertising.tech.mos.ru/banner.php?site_id=vo&rand_id=ZWI&type=left_banners_2&ref_url='+encodeURIComponent(document.location.href)+'"></iframe></div>');
