var settings = {
	
	'force_size':			0,         		// 	if set to 1 all banners will be resized to the width and height in the next to settings
	'img_width':			0,			//	width to resize all banners to, only takes effect if above is 1
	'img_height':			0, 			// 	height to resize all banners to, only takes effect if above is 1
	
	'refresh_time':			4000,			//	the seconds between refreshs of the banners - use 0 to disable
	'refresh_max':			400,				//	maximum number of refreshs on each page load
	
	'duplicate_banners':	0,				//	keep as 0 to make sure the same banner won't show on the same page. will only take effect
											//  if show_banners(); is used more than once. You must make sure you have enough banners to fill
											//  all the slots else the browser may freeze or give a stack overflow error
	
	'location_prefix': 		'adLocation-',	//	The prefix of the IDs of the <div> which wraps the banners - this div is generated dynamically.
											//  a number will be added on the end of this string. adLocation- was used by default before version 1.4.x
											
	'location_class':		'swb',			//  A class to add to all of the <div>s which wrap the banners, ideal to use for styling banners - use .swb img in your CSS	
	
	'window': 				'_blank',		//	Window to open links in, _self = current, _blank = new. Use _top if in a frame!		
	
	'default_ad_loc':		'default'		//	The default adLocation. This is assigned to any banners not given an adLocation in the below banner list
											//  There is no real reason to need to change this
}



/*new banner('Отдых на природе', 				'#', 	'/css/pic/otdih_na_prirode.gif',		'30/04/2019',	'right'),
 new banner('Трансаэротур', 				'http://omsk.transaerotour.com/', 	'/css/pic/tats01.gif',		'30/04/2019',	'left')
 
 **/

var banners = [
	new banner('ОмскВторСырье',			'http://www.omskvtor.ru/', 			'/images/banner_omsk_vtor.gif', 	'30/04/2019',	'right'),
	new banner('Грильман',			'http://grillman.ru/', 			'/css/pic/grillman.jpg', 	'30/04/2019',	'right'),
	new banner('Коммерческая недвижимость',	'http://redmakler.ru/Gallery.aspx', 		'/css/pic/red_makler.gif',		'10/04/2019',	'left')
	
	
]
var used				= 0;
var location_counter	= 0;
var refresh_counter 	= 1;
var map 				= new Array();

function banner(name, url, image, date, loc)
{
	this.name	= name;
	this.url	= url;
	this.image	= image;
	this.date	= date;
	this.active = 1;
	this.oid = 0;
	if(loc != '')
	{
		this.loc = loc;
	}
	else
	{
		this.loc = settings.default_ad_loc;
	}
}
function show_banners(banner_location)
{
    
            
	location_counter = location_counter + 1;
	if(banner_location != '' && banner_location != undefined)
	{
		map[location_counter] = banner_location;
	}
	else
	{
		map[location_counter] = settings.default_ad_loc;
	}
	var html = '<div id="' + settings.location_prefix + location_counter + '" class="' + settings.location_class + '"></div>';
	document.write(html);
	display_banners(location_counter);
            
}
function display_banners(location)
{
	var location_banners	= new Array();
	if(location == '' || !location || location < 0)
	{
		return;
	}
	var am	= banners.length;
	if((am == used) && settings.duplicate_banners == 0) {
		return;
	}
	for(i = 0; i < (banners.length); i++)
	{
		banners[i].oid = i;
		if((banners[i].loc == map[location]) && (banners[i].active == 1))
		{
			location_banners.push(banners[i]);
		}
	}
	var rand	= Math.floor(Math.random()*location_banners.length);	
	var bn 		= location_banners[rand];
	var image_size 	= (settings.force_size == 1) ? ' width="' + settings.img_width + '" height="' + settings.img_height + '"' : '';
	var html 		= '<a href="' + bn.url + '" title="' + bn.name + '" target="' + settings.window + '"><img  style="padding-left:10px" border="0" src="' + bn.image + '"' + image_size + ' alt="' + bn.name + '" /></a>';
	var now		= new Date(); 
	var input	= bn.date;
	input		= input.split('/', 3);
	var end_date	= new Date();
	end_date.setFullYear(parseInt(input[2]), parseInt(input[1]) - 1, parseInt(input[0]));
	if((now < end_date) && bn.active == 1) 
	{
		var location_element = document.getElementById(settings.location_prefix + location);
		if(location_element == null)
		{
			alert('banner rotator\nError: adLocation doesn\'t exist!');
		}
		else
		{
			location_element.innerHTML = html;
			if(settings.duplicate_banners == 0)
			{
				banners[bn.oid].active = 0;
				used++;
			}
			return;
		}
	}
	else
	{
		display_banners(location);
	}
	return;
}
function refresh_banners()
{
	if((refresh_counter == settings.refresh_max) || settings.refresh_time < 1)
	{
		clearInterval(banner_refresh);  
	}
	used = 0;
	for(j = 0; j < (banners.length); j++)
	{
		banners[j].active = 1;
	}
	for(j = 1; j < (location_counter+1); j++)
	{
		display_banners(j);
	}
	refresh_counter++;
}
var banner_refresh = window.setInterval(refresh_banners, settings.refresh_time);
