/*
powered by http://www.homepictures.ru, 2008

значения по умолчанию
var Settings = {
BlockId : "links",
Delimeter : "<br>",
yandexText : "Покушай.Ру",
directText : "Реклама",
directLink : "http://www.pokushay.ru/support.html",
addText : "",
addLink : "",
allText : "",
allLink : "",
Direction:"vertical"
imgClass:false
};
Чтобы перекрыть значения о умолчанию надо объявить объект linkSettings и переопределить
необходимые вам свойства этого объекта

Описание свойств
BlockId - идентификатор (id) тега-контейнера, в который заключены ссылки
Delimeter - разделитель между ссылками
yandexText - наименование владельца системы контекстной рекламы (Яндекс)
directText - наименование системы контекстной рекламы (Директ)
directLink - ссылка на сайт системы контекстной рекламы (http://direct.yandex.ru)
addText - текст "Добавить объявление"
addLink - ссылка на страницу "Добавления объявления" ("#")
allText - текст "Все объявления",
allLink : ссылка на страницу "Все объявления" ("#")
Direction - направление блока (vertical или horizontal)
imgClass - false, если не отображать умеьшенные копии, иначе класс для отображения копии

*/

function chameleon(s){
	this.s = {
	BlockId:"reklamaPo",
	Delimeter:"<br>",
	yandexText:"Pokushay.Ru",
	directText:"Реклама",
	allText:"",
	addText:"",
	directLink:"http://www.pokushay.ru/support.html",
	allLink:"",
	addLink:"",
	Direction:"vertical",
	imgClass:true
	};
	if(typeof(s)!='undefined'){
		for(var i in this.s) if(typeof(s[i])!='undefined') this.s[i] = s[i];
	}
	var o = document.getElementById(this.s.BlockId); if(!o) return;
	var text = this.trim(o.innerHTML); if(text=='') return;
	var re = new RegExp(this.s.Delimeter,"ig");
    var tmp = text.split(re);
	var links = [];
	for(var i=0; i<tmp.length; i++){ var l = this.GetContext(tmp[i]); if(l!==null) links[i] = l; }
	if(this.s.Direction=="vertical")  this.ShowVertical(links, o);
	else this.ShowHorizontal(links, o);
}
chameleon.prototype.ShowVertical = function(links, o){
	this.DrawHeader(o);
	var hTable = this.ce('TABLE');
	with(hTable) { width="100%"; border=0; cellSpacing=0; cellPadding=0; className="yaAds"; }
	var hBody = this.ce('TBODY');
	var hTr, a, img;
	for(var i=0; i<links.length; i++){
		hTr = this.ce('TR');
		hTd = this.ce('TD');
		if(this.s.imgClass!==false){
			img = this.ce('IMG');
			img.src='http://images.websnapr.com/?url=http%3A%2F%2F'+links[i].site; 
			img.width = 70; img.height=50;
			img.className = this.s.imgClass;
			hTd.appendChild(img);
		}
		a = this.ce('A'); a.href=links[i].url; a.appendChild(this.ctn(links[i].title));
		hTd.appendChild(a);
		hTd.appendChild(this.ctn(links[i].text));
		a = this.ce('A'); a.href=links[i].url; a.className="yaSite"; a.appendChild(this.ctn(links[i].site));
		hTd.appendChild(a);
		hTr.appendChild(hTd);
		hBody.appendChild(hTr);
	}
	hTable.appendChild(hBody);
	o.appendChild(hTable);
}
chameleon.prototype.ShowHorizontal = function(links, o){
	this.DrawHeader(o);
	var hTable = this.ce('TABLE');
	with(hTable) { width="100%"; border=0; cellSpacing=0; cellPadding=0; className="yaAds"; }
	var hBody = this.ce('TBODY');
	var hTr = this.ce('TR');
	var w = Math.round(100/links.length);
	var a, img;
	for(var i=0; i<links.length; i++){
		hTd = this.ce('TD');
		hTd.width = w+"%";
		if(this.s.imgClass!==false){
			img = this.ce('IMG');
			img.src='http://images.websnapr.com/?url=http%3A%2F%2F'+links[i].site; 
			img.width = 202; img.height=152;
			img.className = this.s.imgClass;
			hTd.appendChild(img);
		}
		a = this.ce('A'); a.href=links[i].url; a.appendChild(this.ctn(links[i].title));
		hTd.appendChild(a);
		hTd.appendChild(this.ctn(links[i].text));
		a = this.ce('A'); a.href=links[i].url; a.className="yaSite";
		a.appendChild(this.ctn(links[i].site));
		hTd.appendChild(a);
		hTr.appendChild(hTd);
	}
	hBody.appendChild(hTr);
	hTable.appendChild(hBody);
	o.appendChild(hTable);
}
chameleon.prototype.DrawHeader = function(o){
	o.innerHTML='';
	var Table = this.ce('TABLE');
	with(Table) { width="100%"; border=0; cellSpacing=0; cellPadding=0; }
	var Body = this.ce('TBODY');
	var Tr = this.ce('TR');
	/* 1 td */
	var Td = this.ce('TD'); Td.className = "yaHead1";
	var Div = this.ce('DIV'); Div.className = "yandex";
	Div.appendChild(this.ctn(this.s.yandexText));
	Td.appendChild(Div);
	Div = this.ce('DIV'); Div.className = "direct";
	var a = this.ce('A'); a.href = this.s.directLink; a.target = "_blank"; 
	a.appendChild(this.ctn(this.s.directText));
	Div.appendChild(a);
	Td.appendChild(Div);
	Tr.appendChild(Td);
	/* 2 td */
	Td = this.ce('TD'); Td.className = "yaHead2";
	Div = this.ce('DIV');
	a = this.ce('A'); a.href=this.s.allLink; a.target = "_blank";
	a.appendChild(this.ctn(this.s.allText));
	Div.appendChild(a);
	Td.appendChild(Div);
	Div = this.ce('DIV');
	a = this.ce('A'); a.href=this.s.addLink; a.target = "_blank"; a.appendChild(this.ctn(this.s.addText));
	Div.appendChild(a);
	Td.appendChild(Div);
	Tr.appendChild(Td);
	Body.appendChild(Tr);
	Table.appendChild(Body);
	o.innerHTML='';
	o.appendChild(Table);
}
chameleon.prototype.GetContext = function(thecode){
	thecode = this.trim(thecode.replace(/\s+/, ' '));
	if(thecode.match(/(.*)<a [^>]*href="([^"]+)"[^>]*>([^<]*)<\/a>(.*)/i)=== null) return null;
	var text = RegExp.$1=='' ? RegExp.$4 : RegExp.$1+RegExp.$3+RegExp.$4;
	var url = RegExp.$2;
	var title = RegExp.$3;
	if(text=='') text = title;
	var site = url.replace(/^http:\/\//i, '');
	site = site.replace(/\/.*$/i, '');
	return {url:url, title:title, text:text, site:site };
}
chameleon.prototype.trim = function(str){ return str.length>0 ? str.replace( /(^\s+|\s+$)/, "" ) : ""; }
chameleon.prototype.ce = function(tag){ return document.createElement(tag); }
chameleon.prototype.ctn = function(t){ return document.createTextNode(t); }