
function wsmBrowser() {
  var userAgent;
  var browserType = [];
  var i;

  this.isIE = false;
  this.isFF = false;
  this.version = null;

  userAgent = navigator.userAgent;

  browserType[0] = "MSIE";
  browserType[1] = "Opera";
  browserType[2] = "Firefox"
  browserType[3] = "Chrome"
  if ((i =  userAgent.indexOf(browserType[0])) >= 0) {
    this.isIE = true;
    this.version = parseFloat(userAgent.substr(i + browserType[0].length));
    return;
  }
  if ((i =  userAgent.indexOf(browserType[1])) >= 0) {
    this.isIE = true;
    this.version = parseFloat(userAgent.substr(i + browserType[1].length));
    return;
  }
  if ((i = userAgent.indexOf(browserType[2])) >= 0) {
    this.isFF = true;
    this.version = parseFloat(userAgent.substr(i + browserType[2].length));
    return;
  }
  if ((i = userAgent.indexOf(browserType[3])) >= 0) {
    this.isFF = true;
    this.version = parseFloat(userAgent.substr(i + browserType[3].length));
    return;
  }

  this.isIE = true;
  return;
}

var browser = new wsmBrowser();

// *************** Работа с Cookie ***************
function setCookie(c_name,value,expiredays) {
  var exdate = new Date();
  exdate.setDate(exdate.getDate()+expiredays);
  var dom = ";domain=." + document.domain + ';path=/';
  document.cookie = c_name +  "=" + escape(value)+ ((expiredays==null) ? "" : ";expires=" + exdate.toGMTString()) + dom;
}

function getCookie(c_name) {
  if (document.cookie.length > 0) {
    c_start = document.cookie.indexOf(c_name + "=");
    if (c_start != -1) {
      c_start = c_start + c_name.length+1;
      c_end = document.cookie.indexOf(";", c_start);
      if (c_end == -1) c_end = document.cookie.length;
      return unescape(document.cookie.substring(c_start, c_end));
    }
  }
  return "";
}
// *************** Работа с Cookie (КОНЕЦ) ***************


//////////////////////////////////////////////////////////////////////////////////////////
// ИНФО
//////////////////////////////////////////////////////////////////////////////////////////

var reclItems = new Array();
	reclItems[0] = {'img': '/tpl/base/img/reclImg.png',
	  'data': {
      0: {
          't': 'Платежный календарь для 1С Бухгалтерии 8',
          'st': '15 ДНЕЙ БЕСПЛАТНО!',
          'd': ' - Контроль своевременности поступления платежей от покупателей<br> - Управление расчетами с поставщиками, сотрудниками и бюджетом<br> - Комплексный подход к планированию и управлению финансами' ,
          'h': '/programs/programma-platezhnyi-kalendar/obzor-vozmozhnostey.html',
          'bgp': '-160' },
      1: {
          't': 'Учет документов для 1С Бухгалтерии 8',
          'st': '15 ДНЕЙ БЕСПЛАТНО!',
          'd': ' - Учет ВХОДЯЩЕЙ / ИСХОДЯЩЕЙ корреспонденции, договоров, документов<br> - Учет ВНУТРЕННИХ приказов, служебных записок и прочих документов<br> - Ведение единой информационной базы документов организации' ,
          'h': '/programs/programma-uchet-documentov/obzor-vozmozhnostey.html',
          'bgp': '0' },

      2: {
          't': 'Управление финансами для 1С Бухгалтерии 8',
          'st': '15 ДНЕЙ БЕСПЛАТНО!',
          'd': ' - Управление заявками на платежи: регистрация, утверждение, исполнение<br> - Управление бюджетом движения денежных средств предприятия<br> - Календарное планирование платежей и поступлений',
          'h': '/programs/programma-upravlenie-finansami/obzor-vozmozhnostey.html',
          'bgp': '-480' },

	    3: {
          't': 'Бюджет движения ДС для 1С Бухгалтерии 8',
          'st': '15 ДНЕЙ БЕСПЛАТНО!',
          'd': ' - Планирование и контроль поступления денежных средств<br> - Бюджетирование и контроль за расходами предприятия<br> - Оперативное календарное планирование денежных потоков' ,
          'h': '/programs/programma-bdds/obzor-vozmozhnostey.html',
          'bgp': '-320' }

}};

var recl = false;

function reclBlock(_data) {
	this.data = _data;
	this.img = false;

	this.shadowOpacity = 0;

	this.title = false;
	this.titleHref = false;
	this.subTitle = false;
	this.subTitleHref = false;
	this.descr = false;
	this.descrHref = false;
	this.btns = new Array();
	this.curBlock = 0;
	this.curSlide = 0;
	this.nextSlide = false;
	this.timeout = false;
	this.doShow = true;

	this.showSlide = rbShowSlide;
	this.hide = rbHide;
	this.show = rbShow;

	// определяем, какой рекламный блок показываем
	var curRecBlock = parseInt(getCookie('lastRecBlock'));
	if (curRecBlock == NaN) curRecBlock = Math.floor(Math.random() * reclItems.length);
	else {
		curRecBlock++;
		if (!reclItems[curRecBlock]) curRecBlock = 0;
	}
	setCookie('lastRecBlock', curRecBlock);
	this.curBlock = curRecBlock;

	var html = '';

	html += '<style type="text/css">';
	html += '#reclBlockDiv {background-color: #fff; border: 1px solid #000; padding: 1px; margin-bottom: 24px;}';
	html += '#reclBlock { background-color: #003f40; padding: 6px 10px 4px; height: 150px; width: 100%; margin: 0px; }';
	html += '#reclBlock td { padding: 4px; border: none; }';
	html += '#reclBlock #reclBlockImg { width: 150px; height: 140px; background: url(http://ufamax.ru/tpl/base/img/systecs-boxes.png) no-repeat 0px center; padding: 0px; }';

	html += '#reclBlock #reclBlockTitle {padding:4px 6px 0px; text-align: left; overflow: hidden; height: 38px;}';
	html += '#reclBlock #reclBlockTitleHref { color: #faface; font-size: 20pt; font-weight: normal; text-decoration: none;  }';
	html += '#reclBlock #reclBlockTitleHref:hover {color: orange; }';

	html += '#reclBlock #reclBlockSubTitle { padding: 0px 18px 16px 0px; width: 100px; text-align:right; vertical-align: bottom; line-height: 150%; }';
	html += '#reclBlock #reclBlockSubTitleHref { color: #FfFfa0; font-size: 10pt; font-weight: bold; text-decoration: none; }';
	html += '#reclBlock #reclBlockSubTitleHref:hover { color: orange; }';

	html += '#reclBlock #reclBlockDescr { padding: 0px 6px 0px 10px; overflow-y: hidden; line-height: 150%; height: 80px; }';
	html += '#reclBlock #reclBlockDescrHref {color: #fff; font-size: 10pt; text-decoration: none; }';
	html += '#reclBlock #reclBlockDescrHref:hover { color: #faface; }';

	html += '#reclBlock #reclBtnsCont { text-align: center; padding: 0px 0px 4px; vertical-align: bottom; height: 30px;}';
	html += '#reclBlock #reclBtns {  border-spacing: 6px 0px; border-collapse: separate; margin: auto; width: 0px; }';
	html += '#reclBlock #reclBtns td { cursor: pointer; padding: 0px; vertical-align: middle; text-align: center; width: 22px; height: 22px; color: #fff; background-color: #396b6b; font-size: 9pt; border: 1px solid #ccc; }';
	html += '#reclBlock #reclBtns td.cur {color: #fff; background-color: #719595; border: 1px solid #fff; cursor: none; }	';
	html += '</style>';

	html += '<div id="reclBlockDiv">';
	html += '<table id="reclBlock" onmouseover="rbShowStop();" onmouseout="rbShowStart();">';


	html += '<tr>';

	html += '<td id="reclBlockImg" rowspan="3"></td>';

	html += '<td style="padding-bottom:0px; padding-top:0px;" colspan="2">';
	html += '<div id="reclBlockTitle"><a id="reclBlockTitleHref" href="/" target="_blank" onclick="return rbShowPage(this);">&nbsp;</a></div>';
	html += '</td>';

	html += '</tr>';


	html += '<tr>';

	html += '<td style="padding:0px;">';
	html += '<div id="reclBlockDescr"><a id="reclBlockDescrHref" href="/" target="_blank" onclick="return rbShowPage(this);">&nbsp;</a></div>';
	html += '</td>';

	html += '<td id="reclBlockSubTitle" rowspan="2"><a id="reclBlockSubTitleHref" href="/" target="_blank" onclick="return rbShowPage(this);">&nbsp;</a></td>';

	html += '</tr>';


	html += '<tr>';
	html += '<td id="reclBtnsCont">';
	html += '<table id="reclBtns">';
	html += '<tr>';


	for (i = 0; i < 4; i++)  {
		html += '<td onclick="showSlide(' + i + ');">' + (i + 1) + '</td>';
	}
	html += '</tr>';
	html += '</table>';
	html += '</td>';
	html += '</tr>';

	html += '</table>';
	html += '</div>';
	document.write(html);

	this.img			= document.getElementById('reclBlockImg');
	this.title		= document.getElementById('reclBlockTitle');
	this.titleHref= document.getElementById('reclBlockTitleHref');
	this.subTitle	= document.getElementById('reclBlockSubTitle');
	this.subTitleHref	= document.getElementById('reclBlockSubTitleHref');
	this.descr		= document.getElementById('reclBlockDescr');
	this.descrHref= document.getElementById('reclBlockDescrHref');

	this.btns = document.getElementById('reclBtnsCont').getElementsByTagName('TD');

	this.showSlide();
}

function rbShowSlide() {
	var curSlide = this.data[this.curBlock]['data'][this.curSlide];

	this.img.style.opacity			= this.shadowOpacity;
	this.title.style.opacity		= this.shadowOpacity;
	this.subTitle.style.opacity = this.shadowOpacity;
	this.descr.style.opacity		= this.shadowOpacity;

	this.img.style.backgroundPosition = '' + curSlide['bgp'] + 'px';

	var mainDomain = 'systecs.ru';
	var href = 'http://' + mainDomain + '' + curSlide['h'];
	this.titleHref.href				= href;
	this.titleHref.innerHTML	= curSlide['t'];
	this.subTitleHref.href		= href;
	this.subTitleHref.innerHTML	= curSlide['st'];
	this.descrHref.href				= href;
	this.descrHref.innerHTML	= curSlide['d'];

	this.timeout = setTimeout('recl.show();', 10);
}

function rbShow() {
	this.shadowOpacity += 0.02;
	if (this.shadowOpacity > 1) {
		this.shadowOpacity = 1;
	}
	this.img.style.opacity			= this.shadowOpacity;
	this.title.style.opacity		= this.shadowOpacity;
	this.subTitle.style.opacity = this.shadowOpacity;
	this.descr.style.opacity		= this.shadowOpacity;

	if (this.shadowOpacity == 1) {
		this.btns[this.curSlide].className = 'cur';
		clearTimeout(this.timeout);

		if (!this.doShow) {
			this.timeout = setTimeout('recl.showSlide();', 4000);
			return;
		}

		this.timeout = setTimeout('recl.hide();', 4000);
		return;
	} else if (this.shadowOpacity >= 0.2 && this.shadowOpacity < 0.22) {
		this.btns[this.curSlide].className = 'cur';
	}

	this.timeout = setTimeout('recl.show();', 10);
}

function rbHide() {
	this.shadowOpacity -= 0.03;
	if (this.shadowOpacity < 0) {
		this.shadowOpacity = 0;
	}
	this.img.style.opacity			= this.shadowOpacity;
	this.title.style.opacity		= this.shadowOpacity;
	this.subTitle.style.opacity = this.shadowOpacity;
	this.descr.style.opacity		= this.shadowOpacity;

	if (this.shadowOpacity == 0) {
		for (key in this.btns) {
			this.btns[key].className = '';
		}

		if (this.nextSlide === false) {
			this.curSlide++;
		  if (this.curSlide == 4) {
		  	this.curSlide = 0;
		  }
		} else {
			this.curSlide = this.nextSlide;
			this.nextSlide = false;
		}

		this.timeout = setTimeout('recl.showSlide();', 300);
		return;
	}

	this.timeout = setTimeout('recl.hide();', 10);
}

function rbShowStop() {
	recl.doShow = false;
	clearTimeout(recl.timeout);
	recl.showSlide();
}

function rbShowStart() {
	recl.doShow = true;
	clearTimeout(recl.timeout);
	recl.timeout = setTimeout('recl.showSlide();', 1);
}

function showSlide(_index) {
	recl.doShow = false;
	recl.nextSlide = _index;
	clearTimeout(recl.timeout);
	if (browser.isIE) {
		for (key in recl.btns) {
			recl.btns[key].className = '';
		}
		recl.curSlide = recl.nextSlide;
		recl.nextSlide = false;
		recl.showSlide();
	} else {
		recl.timeout = setTimeout('recl.hide();', 10);
	}
}

function rbShowPage() {
	setCookie('recRef', genStrID(recl.titleHref.innerHTML));
	return true;
}

function userRecl() {
	recl = new reclBlock(reclItems);
}

function transitionURL(obj) {
	setCookie('recRef', genStrID(obj.parentNode.getElementsByTagName('A')[0].innerHTML));
	return true;
}

function genStrID(str) {
	var arrru = new Array ("[\.]", "А","а","Б","б","В","в","Г","г","Д","д","Е","е","Ё","ё","Ж", "ж", "З","з","И","и","Й","й","К","к","Л","л","М","м","Н","н","О","о","П","п","Р","р","С","с","Т","т","У","у","Ф","ф","Х","х","Ц","ц","Ч", "ч", "Ш", "ш", "Щ", "щ",  "Ъ","ъ","Ы","ы","Ь","ь","Э","э","Ю", "ю", "Я", "я");
	var arren = new Array ("_",    "A","a","B","b","V","v","G","g","D","d","E","e","E","e","Zh","zh","Z","z","I","i","Y","y","K","k","L","l","M","m","N","n","O","o","P","p","R","r","S","s","T","t","U","u","F","f","H","h","C","c","Ch","ch","Sh","sh","Sch","sch","","", "Y","y","", "", "E","e","Yu","yu","Ya","ya");
  for(var i=0; i<arrru.length; i++) {
   	var litnow = new RegExp(arrru[i], "g");
   	str = str.replace(litnow, arren[i]);
  }
	return str;
}
