


function ClearParams (url)
{
	url = url.replace(/\?\&/, '?');
	url = url.replace(/\&\&/, '&');
	url = url.indexOf('?') == url.length - 1 ? url.substr(0, url.length-1) : url;
	url = url.indexOf('&') == url.length - 1 ? url.substr(0, url.length-1) : url;
	return url;
}

function SetParam(url, param, value)
{
	value = value.toString();
	if (param == "" && value == "")
	{
		var newurl = url.substr(0, url.indexOf("html") == -1 ? url.length : url.indexOf("html") + 4);
		return ClearParams(newurl);
	}

	if (value == "")
	{
		var start = url.indexOf(param + '=');
		if (start == -1)
		{
			return ClearParams(url);
		}
		var stop = url.indexOf("&", start+1);
		if (stop == -1)
		{
			stop = url.length;
		}
		var newurl = url.substring(0, start) + url.substring(stop);
		return ClearParams(newurl);
	}





	var start = url.indexOf(param + '=');
	if (start == -1)
	{
	var newurl = url + (url.indexOf('?') == -1 ? '?' : '&') + param + '=' + value;
	return ClearParams(newurl);
	}

	var stop = url.indexOf("&", start+1);
	if (stop == -1)
	{
		stop = url.length;
	}
	var newurl = url.substring(0, start) + (url.indexOf('?') == -1 ? '?' : '&') + param + "=" + value + url.substring(stop);
	return ClearParams(newurl);

}

function GetParam(url, param)
{
	var value;

	var start1 = url.indexOf(param + '=');
	if (start1 == -1)
	{
		value = '';
		return value;
	}

	var start2 = url.indexOf('=', start1) + 1;

	var stop = url.indexOf('&', start2);
	if (stop == -1)
	{
		stop = url.length;
	}

	value = url.substring(start2, stop);
	
	return value;
}


function lj_A ()
{
	document.getElementById ('lj').innerHTML = ', <a href="http://artbaiter.livejournal.com">жж</a>';
	return;
}


function Ctrl (i)
{
	var hint = '';

	switch (navigator.userAgent.indexOf("Opera") != -1) {
		case true:
			switch (navigator.appVersion.indexOf("Mac") != -1) {
				case true:
					hint='<img src="img/_ctrl_apple.gif" width="31" height="13" alt="">';
					break;
					
				default:
					hint='<img src="img/_ctrl.gif" width="15" height="13" alt="">';
			}
			break;
			
		default:
			hint='<img src="img/_ctrl.gif" width="15" height="13" alt="">';
	}
	document.getElementById(i).innerHTML = hint;
	return;
}

function Keys (event)
{
	if (!document.getElementById) return;
	if (window.event) event = window.event;
	if (event.ctrlKey) {
		var link = null;
		var mark = '';
		switch (event.keyCode ? event.keyCode : event.which ? event.which : null) {
			case 0x25:
				link = document.getElementById ('arrows_01');
				mark = 'Ctrl_Left';
				break;
			case 0x27:
				link = document.getElementById ('arrows_02');
				mark = 'Ctrl_Right';
				break;
			case 0x26:
				link = document.getElementById ('arrows_03');
				mark = 'Ctrl_Up';
				break;
			case 0x28:
				link = document.getElementById ('arrows_04');
				mark = 'Ctrl_Down';
				break;
			case 0x21:
				link = document.getElementById ('arrows_05');
				mark = 'Ctrl_PgUp';
				break;
			case 0x22:
				link = document.getElementById ('arrows_06');
				mark = 'Ctrl_PgDn';
				break;
			case 0x24:
				link = document.getElementById ('arrows_07');
				mark = 'Ctrl_Home';
				break;
			case 0x23:
				link = document.getElementById ('arrows_08');
				mark = 'Ctrl_End';
				break;
		}

		if (link && link.href) document.location=SetParam(link.href, 'source', mark);
	}			
}


function ReParam(wintune, paraName, newValue)
{
	var i1 = ((wintune.indexOf(paraName)+paraName.length+1) > wintune.length) ? wintune.length : (wintune.indexOf(paraName)+paraName.length+1);
	var i2 = (wintune.indexOf(',', i1) != -1) ? wintune.indexOf(',', i1) : wintune.length;
	return  wintune.substring(0, i1) + newValue + wintune.substring(i2);
}

function Check(wintune)
{
	var i1 = ((wintune.indexOf('height=')+7) > wintune.length) ? wintune.length : (wintune.indexOf('height=')+7);
	var i2 = (wintune.indexOf(',', i1) != -1) ? wintune.indexOf(',', i1) : wintune.length;
	var numdigit = wintune.substring(i1, i2);
	var wt = wintune;
	if (numdigit > screen.availHeight) {
		numdigit =  (screen.availHeight - 50);
		wt = ReParam (wt, 'top', 5);
		wt = ReParam (wt, 'screenY', 5);
		i1 = ((wt.indexOf('height=')+7) > wt.length) ? wt.length : (wt.indexOf('height=')+7);
		i2 = (wt.indexOf(',', i1) != -1) ? wt.indexOf(',', i1) : wt.length;
	}
	wt =  wt.substring(0, i1) + numdigit + wt.substring(i2);

	i1 = ((wt.indexOf('width=')+6) >wt.length) ? wt.length : (wt.indexOf('width=')+6);
	i2 = (wt.indexOf(',', i1) != -1) ? wt.indexOf(',', i1) : wt.length;
	var numdigit = wt.substring(i1, i2);
	var wt2 = wt;
	if (numdigit > screen.availWidth) {
		numdigit =  screen.availWidth - 20;
		wt2 = ReParam (wt2, 'left', 20);
		wt2 = ReParam (wt2, 'screenX', 20);
		i1 = ((wt2.indexOf('width=')+6) > wt2.length) ? wt2.length : (wt2.indexOf('width=')+6);
		i2 = (wt2.indexOf(',', i1) != -1) ? wt2.indexOf(',', i1) : wt2.length;
	}
	wt2 =  wt2.substring(0, i1) + numdigit + wt2.substring(i2);

	return wt2;
}

function OpenWnd(filename, winname, wintune)
{






	window.open(filename, winname, Check(wintune));
	return false;
}


function MarkA(linkid, param, value)
{
	try{
		if (document.getElementById(linkid).href)
		{
			var mark = linkid.substring(0, linkid.indexOf('_'));
			var originalHref = document.getElementById(linkid).href;
			document.getElementById(linkid).href = SetParam(document.getElementById(linkid).href, 'source', mark);
			document.getElementById(linkid).href = SetParam(document.getElementById(linkid).href, param, value);
		}
	}catch(e){return;}

	return;
}

function MarkACircle(IDName, repeat, param, value)
{
	var no = '';
	var linkid = '';
	for (var i = 1; i <= repeat; i++)
	{
		if (i<10)
		{
			no = '0' + i.toString();
		}
		else
		{
			no = i.toString();
		}
		linkid=IDName + no.toString();
		MarkA(linkid, param, value);
	}
	return;
}

function MarkAllA(param, value)
{

	if (value == '')
	{
		value = GetParam(document.location.href, param);

		if (value == '')
		{
			value = 'logo';
		}
	}

	MarkACircle ('arrows_', 9, param, value);
	MarkACircle ('footer_', 6, param, value);
	MarkACircle ('content_', 25, param, value);
	MarkACircle ('keywords_', 10, param, value);
	MarkACircle ('logo_', 1, param, value);
	MarkACircle ('m01a_', 3, param, '');
	MarkACircle ('m02a_1', 20, param, value);
	MarkACircle ('m02a_2', 20, param, value);
	MarkACircle ('m02a_3', 15, param, value);
	MarkACircle ('m02a_4', 15, param, value);
	MarkACircle ('m03a_', 25, param, value);
	MarkACircle ('map_', 1, param, value);
	MarkACircle ('iHead_', 4, param, value);
	MarkACircle ('iPict_', 4, param, value);
	MarkACircle ('BigPict_', 16, param, value);
	

	if (document.getElementById ('arrows_09').href != '')
	{

		if (GetParam(document.location.href, 'auto') == 'yes')
		{
			document.getElementById('auto').innerHTML = '<a href="javascript:StopAuto()"><img src="img/_Auto_stop.gif" width="18" height="13" alt="Остановить слайд-шоу" title="Остановить слайд-шоу"></a>';
		}
			else
		{
			document.getElementById('auto').innerHTML = '<a href="javascript:StartAuto()"><img src="img/_Auto.gif" width="18" height="13" alt="Сайт как слайд-шоу" title="Сайт как слайд-шоу"></a>';
		}

	}

	return;
}



function goToURLtag(url)
{
	url = SetParam(url, 'source', 'content');
	url = SetParam(url, 'tag', GetParam(document.location.href, 'tag'));
	document.location.href = url;
}


function StartAuto()
{
	document.location=SetParam(document.getElementById ('arrows_09').href, 'auto', 'yes');
	return;
}

function StopAuto()
{
	window.clearTimeout(id_timeout);
	document.getElementById('auto').innerHTML = '<a href="javascript:StartAuto()"><img src="img/_Auto.gif" width="18" height="13" alt="Сайт как слайд-шоу" title="Сайт как слайд-шоу"></a>';
	return;
}

function Auto(auto_time)
{
	if (document.location.href.indexOf('Artbait_Office_Address_01.html') != -1)
	{
		YaMap();
	}

	if (auto_time == '')
	{
		auto_time = 2500;
	}

	if (document.getElementById ('arrows_09').href != '' && GetParam(document.location.href, 'auto') == 'yes')
	{
		id_timeout = window.setTimeout ("document.location=SetParam(document.getElementById ('arrows_09').href, 'auto', 'yes')", auto_time);
	}
	return;
}


function onSearchField(Field)
{
	Field.style.color = 'black';
	if (Field.value == 'Поиск по сайту')
	{
		Field.value = '';
	}
	return false;
}

function offSearchField(Field)
{
	Field.style.color = 'gray';
	if (Field.value == '')
	{
		Field.value = 'Поиск по сайту';
	}
	return false;
}


function div_onoff(div_id, onoff)
{
	if (onoff)
	{
		document.getElementById(div_id).style.display = 'block';
	}
	else
	{
		document.getElementById(div_id).style.display = 'none';
	}

	return;
}
function BrandTags(Index, Href, All, Logo, Package, Name, Video, Semi, Ice, TV, Plant)
{
	this.index = Index;
	this.href = Href;
	this.all = All;
	this.logo = Logo;
	this.pack = Package;
	this.name = Name;
	this.video = Video;
	this.semi = Semi;
	this.ice = Ice;
	this.tv = TV;
	this.plant = Plant;
}

var Brands = new Array();

Brands[0] = new BrandTags("116", '', 1, 1, 0, 0, 0, 0, 0, 0, 0);
Brands[1] = new BrandTags("203", '', 1, 1, 1, 'Portfolio_30m_Branding_01.html', 0, 1, 0, 0, 0);
Brands[2] = new BrandTags("201", '', 1, 1, 0, 'Portfolio_Bar_Branding_01.html', 0, 1, 0, 0, 0);
Brands[3] = new BrandTags("211", '', 1, 1, 1, 'Portfolio_Blb_Branding_01.html', 0, 1, 0, 0, 0);
Brands[4] = new BrandTags("218", '', 1, 1, 1, 'Portfolio_BN_Branding_01.html', 0, 1, 0, 0, 0);
Brands[5] = new BrandTags("109", '', 1, 1, 0, 0, 0, 0, 0, 0, 0);
Brands[6] = new BrandTags("107", '', 1, 1, 0, 'Portfolio_CM_Branding_01.html', 0, 0, 0, 0, 0);
Brands[7] = new BrandTags("307", '', 1, 1, 0, 0, 0, 0, 0, 0, 0);
Brands[8] = new BrandTags("208", '', 1, 1, 1, 0, 0, 0, 0, 0, 0);
Brands[9] = new BrandTags("106", '', 1, 1, 0, 0, 'Portfolio_Ekp_Video_01.html', 0, 0, 1, 0);
Brands[10] = new BrandTags("210", '', 1, 1, 1, 'Portfolio_EO_Branding_01.html', 0, 0, 0, 0, 0);
Brands[11] = new BrandTags("204", '', 1, 1, 1, 0, 'Portfolio_FG_Video_01.html', 0, 1, 0, 0);
Brands[12] = new BrandTags("105", '', 1, 1, 0, 0, 0, 0, 0, 0, 0);
Brands[13] = new BrandTags("206", '', 1, 1, 1, 'Portfolio_GTF_Branding_01.html', 'Portfolio_GTF_Video_01.html', 1, 0, 0, 0);
Brands[14] = new BrandTags("214", '', 1, 1, 1, 0, 0, 0, 1, 0, 0);
Brands[15] = new BrandTags("117", '', 1, 1, 0, 0, 0, 0, 0, 0, 0);
Brands[16] = new BrandTags("217", '', 1, 1, 1, 'Portfolio_MC_Branding_01.html', 0, 0, 1, 0, 0);
Brands[17] = new BrandTags("302", '', 1, 1, 0, 0, 0, 0, 0, 0, 1);
Brands[18] = new BrandTags("202", '', 1, 1, 1, 0, 0, 0, 1, 0, 0);
Brands[19] = new BrandTags("305", '', 1, 1, 0, 0, 0, 0, 0, 0, 0);
Brands[20] = new BrandTags("301", '', 1, 1, 0, 0, 0, 0, 0, 0, 1);
Brands[21] = new BrandTags("118", '', 1, 1, 0, 0, 0, 0, 0, 0, 0);
Brands[22] = new BrandTags("303", '', 1, 1, 0, 'Portfolio_Nau_Branding_01.html', 0, 0, 0, 0, 1);
Brands[23] = new BrandTags("209", '', 1, 1, 1, 'Portfolio_Nhd_Branding_01.html', 0, 1, 0, 0, 0);
Brands[24] = new BrandTags("103", '', 1, 1, 0, 0, 0, 0, 0, 0, 0);
Brands[25] = new BrandTags("304", '', 1, 1, 0, 0, 0, 0, 0, 0, 1);
Brands[26] = new BrandTags("212", '', 1, 1, 1, 0, 0, 0, 0, 0, 0);
Brands[27] = new BrandTags("113", '', 1, 1, 0, 'Portfolio_OLv_Branding_01.html', 0, 0, 0, 0, 0);
Brands[28] = new BrandTags("213", '', 1, 1, 1, 'Portfolio_Osb_Branding_01.html', 0, 1, 0, 0, 0);
Brands[29] = new BrandTags("216", '', 1, 1, 1, 0, 0, 0, 1, 0, 0);
Brands[30] = new BrandTags("306", '', 1, 1, 0, 1, 0, 0, 0, 0, 0);
Brands[31] = new BrandTags("207", '', 1, 1, 1, 'Portfolio_Psp_Branding_01.html', 'Portfolio_Psp_Video_01.html', 1, 'Portfolio_Psp_Package_02.html', 0, 0);
Brands[32] = new BrandTags("111", '', 1, 1, 0, 0, 0, 0, 0, 0, 0);
Brands[33] = new BrandTags("102", '', 1, 1, 0, 0, 'Portfolio_RCH_Video_01.html', 0, 0, 1, 0);
Brands[34] = new BrandTags("308", '', 1, 1, 0, 0, 0, 0, 0, 0, 1);
Brands[35] = new BrandTags("115", '', 1, 1, 0, 'Portfolio_Rtg_Branding_01.html', 0, 0, 0, 0, 0);
Brands[36] = new BrandTags("215", '', 1, 1, 1, 'Portfolio_Rub_Branding_01.html', 0, 1, 0, 0, 0);
Brands[37] = new BrandTags("205", '', 1, 1, 1, 0, 0, 1, 0, 0, 0);
Brands[38] = new BrandTags("112", '', 1, 1, 0, 0, 0, 0, 0, 0, 0);
Brands[39] = new BrandTags("110", '', 1, 1, 0, 0, 0, 0, 0, 0, 0);
Brands[40] = new BrandTags("309", '', 1, 1, 0, 0, 0, 0, 0, 0, 0);
Brands[41] = new BrandTags("108", '', 1, 1, 0, 0, 0, 0, 0, 1, 0);
Brands[42] = new BrandTags("104", '', 1, 1, 0, 0, 'Portfolio_VTV_Video_01.html', 0, 0, 1, 0);
Brands[43] = new BrandTags("101", '', 1, 1, 0, 0, 0, 0, 0, 0, 0);
Brands[44] = new BrandTags("114", '', 1, 1, 0, 'Portfolio_Wel_Branding_01.html', 0, 0, 0, 0, 0);

function TagItems(TagIndex, TagName)
{
	this.TagIndex = TagIndex;
	this.TagName = TagName;
}

var Tags = new Array();

Tags[0] = new TagItems('415', 'all');
Tags[1] = new TagItems('414', 'logo');
Tags[2] = new TagItems('413', 'pack');
Tags[3] = new TagItems('412', 'name');
Tags[4] = new TagItems('411', 'video');
Tags[5] = new TagItems('410', 'semi');
Tags[6] = new TagItems('409', 'ice');
Tags[7] = new TagItems('408', 'tv');
Tags[8] = new TagItems('407', 'plant');

function ShowTaggedOnly (TagIndex)
{

	var TagName = '';

	if(TagIndex != '')
	{
		if(TagIndex == '401')
		{
			TagIndex = '415';
		}

		for (var i=0; i<Tags.length; i++)
		{
			if (Tags[i].TagIndex == TagIndex)
			{
				TagName = Tags[i].TagName;
				break;
			}
		}
	}
	else
	{
		TagName = GetParam(document.location.href, 'tag');

		for (var i=0; i<Tags.length; i++)
		{
			if (Tags[i].TagName == TagName)
			{
				TagIndex = Tags[i].TagIndex;
				break;
			}
		}

		if(TagName == '')
		{
			TagIndex = '415';
			TagName = 'all';
		}
	}

	if(document.location.href.indexOf('Portfolio_') != -1)
	{

		var tempInnerHtml;
		var tempurl;
	
		for (var i=0; i<Brands.length; i++)
		{
	
			try
			{
				tempurl = '' + document.getElementById('m02a_' + Brands[i].index).href;
				document.getElementById('m02a_' + Brands[i].index).href = SetParam(tempurl, 'tag', TagName);
			}
			catch(e) {}
	
			try{
	
				if(Brands[i].href == '')
				{
					Brands[i].href = document.getElementById("m02a_" + Brands[i].index).href;
				}
	
				document.getElementById("m02a_" + Brands[i].index).href = Brands[i].href;

	
				if(Brands[i][TagName] != 0)
				{
					if (document.getElementById("m02a_" + Brands[i].index).className == "ri_")
					{
						document.getElementById("m02a_" + Brands[i].index).className = "ri";
					}

					if (document.getElementById("m02a_" + Brands[i].index).className == "ai_")
					{
						document.getElementById("m02a_" + Brands[i].index).className = "ai";
					}
	
					if(Brands[i][TagName] != 1)
					{
						document.getElementById("m02a_" + Brands[i].index).href = Brands[i][TagName];
					}
				}
				else
				{
					if (document.getElementById("m02a_" + Brands[i].index).className == "ri")
					{
						document.getElementById("m02a_" + Brands[i].index).className = "ri_";
					}

					if (document.getElementById("m02a_" + Brands[i].index).className == "ai")
					{
						document.getElementById("m02a_" + Brands[i].index).className = "ai_";
					}
	
				}
	
	
			}catch(e) {}
	
		}
	}

	MarkAllA('tag', TagName);

	if(document.location.href.indexOf('Portfolio__') != -1)
	{
		return;
	}

	for (var i=0; i<Tags.length; i++)
	{
		try{
			document.getElementById('m02a_' + Tags[i].TagIndex).style.color = "black";
		}catch(e){}
	}

	try{
		document.getElementById('m02a_' + TagIndex).style.color = "#B7007F";
	}catch(e){}

	return;

}

document.onkeydown = Keys;

if (document.location.href.indexOf('map.html') != -1)
{
	Ctrl('ctrl_');
}

Ctrl('ctrl');
lj_A();
MarkAllA('tag', '');
ShowTaggedOnly('');


