// ----------------------------------------------------------------------------------------------------------

	var start			= null;
	var trnsp = tmp_tr 		= 100;
	var step = tmp_st		= 20;

	function Class()
	{
		var obj				= this;
		this.func			= function(){};

//		открытие и закрытие тэгов
		this.tags = function()
		{
			if($('tags') && $('tags_list') && $('tags_close'))
			{
				$('tags').onclick = function()
				{
					var parent = this.parentNode.parentNode;
					if(parent.tagName.toLowerCase() == 'form')
					{
						parent.style.height	= '300px';
					}

					this.className			= 'unvis';
					$('tags_close').className	= '';
					$('tags_list').className	= 'tags';
					return false;
				}

				$('tags_close').onclick = function()
				{
					var parent = this.parentNode.parentNode;
					if(parent.tagName.toLowerCase() == 'form')
					{
						parent.style.height	= '55px';
					}

					this.className			= 'unvis';
					$('tags').className		= '';
					$('tags_list').className	= 'unvis';
					return false;
				}
			}
		}


//		в коллекции при нажатии на фото перегружатькартинку
		this.chgCollectionImg_new = function()
		{
			if($('collection') && $('gallery'))
			{
				var elems	= getChild('img', 'collection')
				var cur_elems	= '';

				if(elems)
				{
					for(var i=0; i<elems.length; i++)
					{
						elems[i].onclick = function()
						{
							cur_elems = this.src;
							$('big_photo').style.background = "#fff url('"+this.src.replace('small', 'big')+"') 85% 40% no-repeat";

							var e		= getChild('img', 'gallery');

							if(e)
							{
								for(var i=0; i<e.length; i++)
								{
									if (e[i].src == cur_elems)
									{
										e[i].className = 'img_sel';
									}else{
										e[i].className = '';
									}
								}
								cur_elems = '';
							}
						}
					}
				}
			}
		}();

//		страницы
		this.pager_new = function()
		{

			var elems = getChild('a', 'pager');

			for(var i=0; i<elems.length; i++)
			{
				elems[i].onclick = function()
				{
					var d = getId(this.id);

					if (d)
					{
						pageTop = d;
						var chg_page = parseUrl('get', 'nextpage', '', $$('pager_next').href);
						$$('pager_next').href = $$('pager_next').href.replace('&nextpage='+chg_page, '&nextpage='+(pageTop+1));

						var chg_page = parseUrl('get', 'nextpage', '', $$('pager_prev').href);
						$$('pager_prev').href = $$('pager_prev').href.replace('&nextpage='+chg_page, '&nextpage='+(pageTop-1));

						if ($('page_current'))
						{
							$('page_current').innerHTML	= pageTop;
						}
					}
				}
			}

			$('pager_next').onclick = function()
			{
				var chg_page = parseUrl('get', 'nextpage', '', $$('pager_next').href);
				$$('pager_next').href = $$('pager_next').href.replace('&nextpage='+chg_page, '&nextpage='+(pageTop+1));

				var chg_page = parseUrl('get', 'nextpage', '', $$('pager_prev').href);
				$$('pager_prev').href = $$('pager_prev').href.replace('&nextpage='+chg_page, '&nextpage='+(pageTop-1));

				if ($('page_current'))
				{
					$('page_current').innerHTML	= pageTop;
				}
			}

			$('pager_prev').onclick = function()
			{
				var chg_page = parseUrl('get', 'nextpage', '', $$('pager_next').href);
				$$('pager_next').href = $$('pager_next').href.replace('&nextpage='+chg_page, '&nextpage='+(pageTop+1));

				var chg_page = parseUrl('get', 'nextpage', '', $$('pager_prev').href);
				$$('pager_prev').href = $$('pager_prev').href.replace('&nextpage='+chg_page, '&nextpage='+(pageTop-1));

				if ($('page_current'))
				{
					$('page_current').innerHTML	= pageTop;
				}
			}
		}

//		открытие полного описания в коллекции
		this.openCollectionDescription = function()
		{
			var elems = getChild('a', 'collection');

			for (var i=0; i<elems.length; i++)
			{
				if (elems[i].id)
				{
					elems[i].onclick = function()
					{
						var smalls = getChild('big', this.parentNode.id);
						smalls[0].className = 'full_description';

						return false;
					}
				}
			}
		}


//		закрытие полного описания в коллекции
		this.closeCollectionDescription = function()
		{
			var elems = getChild('a', 'collection');

			for (var i=0; i<elems.length; i++)
			{
				if (elems[i].parentNode.className == 'full_description' || elems[i].parentNode.className == 'unvis')
				{
					elems[i].onclick = function()
					{
						this.parentNode.className = 'unvis';

						return false;
					}
				}
			}
		}


//		выпадающие списки в меню
		this.selectMenu = function()
		{
			if($('line2'))
			{
				var elems = getChild('a', 'line2');

				for (var i=0; i<elems.length; i++)
				{
					elems[i].onmouseover = function()
					{
						var childSpans = getChild('span', this.parentNode.id);

						for(var ii=0; ii<childSpans.length; ii++)
						{
							childSpans[ii].onmouseover = function()
							{
								this.style.color = '#333';
							}

							childSpans[ii].onmouseout = function()
							{
								for(var iii=0; iii<childSpans.length; iii++)
								{
									childSpans[iii].style.color = '#999';
								}
							}

							childSpans[ii].onclick = function()
							{
								var rLink = this.getElementsByTagName('i')[0].innerHTML;
								window.location.href = rLink.replace(/&amp;/g, '&');
								return false;
							}
						}
					}
				}
			}
		}

//		навигация в библиотеке
		this.gemMenu = function()
		{
			if ($('gem_menu'))
			{
				var elems = getChild('a', 'gem_menu');
				var elems_action = getChild('span', 'g2');
				
				if (elems && elems_action)
				{
					for (var ii=0; ii<elems.length; ii++)
					{
						elems[ii].onclick = function()
						{
							for (var i=0; i<elems_action.length; i++)
							{
								elems_action[i].className = '';
							}
							$(this.id+'_action').className = 'sel';
						}
					}
				}
			}
		}


		this.popUp = function(idClick, idChg, classUp, classPop)
		{
			if ($(idClick))
			{
				$(idClick).onclick = function()
				{
					if (idChg)
					{
						$(idChg).className = $(idChg).className == classUp ? classPop : classUp;
					}else{
						$(idClick).className = $(idClick).className == classUp ? classPop : classUp;
					}
					return false;
				}
			}
		}


		this.morePhotoChange = function(id, chg1)
		{

		        if ($(id))
		        {
				var elemsUls = getChild('ul', id);

				if (elemsUls.length)
				{
					var elems = elemsUls[0].getElementsByTagName('img');
				}else{
					return false;
				}

				for (var i=0; i<elems.length; i++)
				{
					elems[i].onclick = function()
					{
						if ($(chg1))
						{
							if (start) {clearInterval(start);}

							start = null;                                                    

//							start = setInterval("chgBackground("+chg1+", '#fff url("+this.src.replace('small', 'big')+") 85% 5% no-repeat')", 100);
							$(chg1).style.background = "#fff url('"+this.src.replace('small', 'big')+"') 85% 40% no-repeat";
						}

						for (var i=0; i<elems.length; i++)
						{
							elems[i].className = '';
						}

						this.className = 'img_sel';
						
						return false;
					}
				}
			}
		}


		this.addToCart = function()
		{
			if ($('cart_add'))
			{
				$('cart_add').onclick = function ()
				{
					if ($('cart')) $('cart').id = 'cart_fill';

					if ($('cart_digit'))
					{
						$('cart_digit').innerHTML = parseInt($('cart_digit').innerHTML) + 1;
//						$('cart_fill').parentNode.parentNode.style.border='solid 1px #c00';
					}
				}
			}
		}


//		в корзине
		this.chgSelect = function(id)
		{
			if ($(id))
			{
				var elems = getChild('select', id);
			
				for (var i=0; i<elems.length; i++)
				{
					elems[i].onchange = function()
					{
						var frm = this.parentNode.parentNode.parentNode;
						
						if (frm.tagName.toLowerCase() == 'form')
						{
							frm.action += this.value;
							frm.submit();
						}
					}
				}
			}
		}


//		изменение стиля на страницах в категории
		this.pager = function()
		{
			var pager = $$('pager');
			
			if(pager)
			{
				var elems = pager.getElementsByTagName('a');

				for(var i=0; i<elems.length; i++)
				{

					var d = getId(elems[i].id);

					if (d && page)
					{

						if (page >= 8)//5
						{
							for(var ii=1; ii<=elems.length; ii++)
							{
								if ($$('p'+ii))
								{
									if (ii>=(page-7) && ii<=(page*1+7))//4
									{
										$$('p'+ii).className = '';
									}else{
										$$('p'+ii).className = 'unvis';
									}
								}
							}

						}else{
							for(var ii=1; ii<=8; ii++)//5
							{
								if ($$('p'+ii))
								{
									$$('p'+ii).className = '';
								}
							}

							for(var ii=15; ii<=elems.length; ii++)//10
							{
								if ($$('p'+ii))
								{
									$$('p'+ii).className = 'unvis';
								}
							}

							for(var ii=1; ii<=elems.length; ii++)
							{
								if($$('p'+ii) && $$('p'+ii).className == 'sel_href')
								{
									$$('p'+ii).className = '';
								}
							}
						}
					}
				}

				$$('p'+page).className = 'sel_href';

				$$('pager_prev').className = page > 1 ? '' : 'unvis';
				$$('pager_next').className = page == (elems.length-2) ? 'unvis' : '';

				var chg_page = parseUrl('get', 'nextpage', '', $$('pager_next').href);
				$$('pager_next').href = $$('pager_next').href.replace('&nextpage='+chg_page, '&nextpage='+(page+1));

				var chg_page = parseUrl('get', 'nextpage', '', $$('pager_prev').href);
				$$('pager_prev').href = $$('pager_prev').href.replace('&nextpage='+chg_page, '&nextpage='+(page-1));

				window.top.pageTop = page;
				$$('page_current').innerHTML = page;
			}
		};
		
		this.printVersion = function(url)
		{
			var attr = "width=600,height=780,menubar=no,personalbar=no,titlebar=no,toolbar=no,location=no,resizable=yes,scrollbars=yes";

			if($('print_up'))
			{
				$('print_up').onclick = function()
				{
					window.open(url, 'print_version', attr);
					return false;
				}
			}
		};
		
		this.toTop = function()
		{
			if(window.top == window && window.top.page !== false && urlTop)
			{
//				window.top.location.href = urlTop;
			}
		}();

	} // end class


/*-----------------------------------------------------------------------------------------------------*/

	chgBackground = function(chg1, bg)
	{
		trnsp -= step;

		chg1.style.opacity = trnsp/100;
		chg1.style.filter = 'alpha(opacity='+trnsp+')';

		if (trnsp == 0)
		{
			trnsp			= tmp_tr
			step			= tmp_st;
			clearTimeout(start);
			chg1.style.background	= bg;
			chg1.style.opacity	= 1;
			chg1.style.filter	= 'alpha(opacity=100)';
		}
	}

/*------------------------------------------------------------------------------------------------------*/

	function $(id)
	{
		return document.getElementById(id);
	}

	function $$(id)
	{
		return window.top.document.getElementById(id);
	}


        function _(str)
	{
		alert(str);
	}


	function getChild(tag, id)
	{
		if (tag)
			return elems = !id ? document.getElementsByTagName(tag) : $(id).getElementsByTagName(tag);
		else
			return false;
	}
						    

	function chgParam(id, param, chg)
	{
		switch (param)
		{
			case 'innerHTML':
				$(id).innerHTML = chg;
				break;

			case 'src':
				$(id).src = chg;
				break;

			case 'width':
				$(id).style.width = chg+'px';
				break;

			case 'id':
				$(id).id = chg;
				break;

			case 'value':
				$(id).value = chg;
				break;			
		}
	}



	function chg(id, val)
	{
		$(id).className = val;
	}


	function arrChg(arr, style)
	{
		for (var i=0; i<arr.length; i++)
		{

			chg(arr[i].id, style);

		}
	}
						

	// определяем наличие в массиве  arr значения val
	// одномерный массив
	function index_of (arr, val)
	{
		for (i=0; i<arr.length; i++)
		{
			if (arr[i] == val)
				return val;
		}

		return false;
	}




	// получаем цифровую составляющую id элемента
	function getId(id)
	{
	
		return id.replace(/\D+/g, '', id);
			
	}



//	получаем параметры из url или строкм
	function parseUrl(part, param, level, str)
	{
	        var result = '';
	        var url = level == 'top' ? window.top.location : (str ? str : window.location);

                switch (part)
                {
                        case 'get':
                                var srch = url.replace('?', '');
                                srch = srch.split("&");
                                for (i in srch)
                                {
                                        if (srch[i].replace(param+'=', '').length != srch[i].length)
                                        {
                                                result = srch[i].replace(param+'=', '');
                                        }
				}
				break;

	                case 'hash':
		        	result = url.hash == param ? 1 : 0;
			        break;
		}

                return result;
	}


	function close_parent_window(url)
	{
		if (opener)
		{
			if (opener.closed)
			{
        			window.open(url, "");
        		}else{
        			var url_p = opener.location.href;
        			var url_c = url;
        			url_p = url_p.replace('\?', '');
        			url_c = url_c.replace('\?', '');
        			if (url_p.search(url_c) == -1)
        			{
        				window.open(url, '');
        			}
        		}

            		self.close();
            		return false;
                }
                return true;
        }