D=document, W=window, IS_OLEG=0;
function noBub(){event.cancelBubble=true}
function noRet(){event.returnValue=false}
function $(id){return D.getElementById(id)}
function _(s){D.write(s)}
function __(s){D.writeln(s)}
B=navigator.appName;
switch(B){
	case "Opera": B="Op"; break;
	case "Microsoft Internet Explorer": B='IE'; break;
	case "Netscape": 
		B=(navigator.userAgent.toLowerCase().indexOf('chrome')>-1)?'CR':'NS';
		//B="NS"; 
		break;
	default: B='';
}
if(B=='IE'){
	BVer=4;
	if(navigator.appVersion.indexOf("MSIE")!=-1)BVer=parseFloat(navigator.appVersion.split("MSIE")[1]);    
}else{
	BVer=parseFloat(navigator.appVersion);
}

function isGoTo(u){
	location.href='http://www.ironsport.com.ua/index.php?creatine='+u;
}

function getPos(o){
	var x=y=0;
	if(o.offsetParent)do{x+=o.offsetLeft;y+=o.offsetTop}while(o=o.offsetParent);
	return [x,y];
}

//- ISCookie -
function ISCookie(n,v,d){
	this.name='ISCookieDef';
	if(typeof(n)!='undefined')this.name=n;
	if(typeof(v)!='undefined'){
		this.set(v,n,d);
	}
	ISCookie.prototype.get = function(n){
		if(typeof(n)!='undefined')this.name=n;
		var nEQ=this.name+"=";
		var ca=D.cookie.split(";");
		for(var i=0;i<ca.length;i++) {
			var c=ca[i];
			while(c.charAt(0)==" ") c=c.substring(1,c.length);
			if (c.indexOf(nEQ)==0) 
				return c.substring(nEQ.length,c.length);
		}
		return null;
	}
	ISCookie.prototype.set = function(v,n,days){
		if(typeof(n)!='undefined')this.name=n;
		var ex="";
		if(typeof(days)=='undefined')days=356;
		if(days){
			var d=new Date();
			d.setTime(d.getTime()+(days*86400000));
			ex="; expires="+d.toGMTString();
		}
		D.cookie=this.name+"="+v+ex;
	}
}

//- Cat Descr
function chVisMoreDescr(e){
	if(!e || !e.lastChild) return;
	var l=e.lastChild.style;
	var f=(l.display=='' || l.display=='none');
	l.display=f?'block':'none';
	l.paddingBottom=f?'12px':'';
}

//- new
var aCurVisDescr=['',''];
var oCurVisDescrCookie=new ISCookie();
function chVisDescrIni(){
	var c=oCurVisDescrCookie;
	var idM=c.get('curVisDescrM');
	var idD=c.get('curVisDescrD');
	var f=c.get('curVisDescrF');
	if(idM && idD){
		if(f) chVisDescr(idM,idD,0);
	}else{
		chVisDescr('liCatMenuSort','catMenuSort',0);
	}
}
function chVisDescr(mId,bId,f){
	var e0=$(mId), e1=$(bId);
	if(aCurVisDescr[0]!=e0){
		aCurVisDescr[0].className='';
		aCurVisDescr[1].className='unvis';
	}
	try{
		if(e0.className=='selected'){
			e0.className='';
			e1.className='unvis';
		}else{
			e0.className='selected';
			e1.className='vis';
		}
		var c=oCurVisDescrCookie;
		c.set(mId,'curVisDescrM');
		c.set(bId,'curVisDescrD');
		c.set(e0.className,'curVisDescrF');
		aCurVisDescr=[e0,e1];
		if(f) noRet();
	}catch(e){}
}

//- SUPPER NEW
var cVMBlockId='', cVMBlockCooName='curVisMenuBlock', cVMBlockCookie=new ISCookie();
function chVisMenuBlockIni(showId,cookieId){
	cVMBlockCooName+=cookieId;
	var c=cVMBlockCookie, id=c.get(cVMBlockCooName);
	try{
		if(id){
			var f=c.get(cVMBlockCooName+'F');
			if(f) chVisMenuBlock(id,0);
		}else{
			chVisMenuBlock('CatMenuBlock'+showId,1);
		}
	}catch(e){}
}
function chVisMenuBlock(bId,f){
	var eM=$('li'+bId), eB=$(bId);
	try{
		if(cVMBlockId!=eB.id){
			$('li'+cVMBlockId).className='';
			$(cVMBlockId).className='catMenuBlockUnvis';
		}
	}catch(e){}
	try{
		if(eM.className=='selected'){
			eM.className='';
			eB.className='catMenuBlockUnvis';
		}else{
			eM.className='selected';
			eB.className='catMenuBlockVis';
		}
		var c=cVMBlockCookie;
		c.set(bId,cVMBlockCooName);
		c.set(eM.className,cVMBlockCooName+'F');
		cVMBlockId=bId;
		if(f) noRet();
	}catch(e){}
}


//- ISFavor -
function ISFavor(){
	this.nameOfClass="oFavor";
	this.f=0;
	this.u=D.location.href;
	this.t=D.title;
	
	this.show = function(){
		if(!this.f){
			this.f=1;
			$('favor').style.display='none';
			$('favorSelect').style.display='block';
		}
		noBub();
	}
	this.hide = function(){
		if(this.f){
			$('favorSelect').style.display='none';
			$('favor').style.display='block';
			this.f=0;
		}
		noBub();
	}
	this.writeLinks = function(o){
		var s='<a href="/" class="favor" onmouseover="noBub()" onmouseout="noBub()" onmousemove="noBub()" ';
		_('<noindex><div id="favor" onmouseover="'+this.nameOfClass+'.show()"></div>');
		_('<div id="favorSelect" onmouseover="noBub()" onmouseout="'+this.nameOfClass+'.hide()">');
		_(s+'onmouseout="noBub()" onclick="'+o+'.homepage(this);return false">Сделать домашней</a>');
		_(s+'onclick="if('+o+'.bookmark())return false" rel="sidebar" title="'+this.t+'">В закладки</a>');
		_('</div></noindex>');
	}
	
	this.homepage = function(o){
		noBub();
		o.style.behavior='url(#default#homepage)';
		o.setHomePage(this.u);
	}

	this.bookmark = function(){
		noBub();
		if(B=='FF')return false;
		else if(B=='IE')W.external.AddFavorite(this.u,this.t);
		else if(B=='Op')return false;
		else alert('Нажмите CTRL+D чтобы добавить страницу в закладки');
		return true;
	}

}


//- ISCompare -
function ISCompare(){
	this.nameOfClass="oCompare";
	this.oCL;
	this.oCId=0;
	this.oCName;
	this.oCVis=0;
	this.aCIds=[];
	this.aCNames=[];
	this.iSTOC0,this.iSTOC1,this.iSTOC2;
	this.iMax=5;
	this.allowBrowser=0;
	this.cooName="oCompare";
	this.sImgsDir="";
	this.sImgs=[];
	this.browser=B;
	this.browserVer=BVer;
	this.allowBrowser=(this.browser=="Op" || this.browser=="IE"/* || this.browser=="NS"*/);
	this.is_oleg=0;
}
ISCompare.prototype.ini = function(sIDir){
	if(typeof(sIDir)!='undefined') this.sImgsDir=sIDir;
	if(this.allowBrowser){
		var c=this.cooGet();
		if(c) this.aCIds=c.split("|");
		this.sImgs=['<img src="'+this.sImgsDir+'sravnit-sportivnoe-pitanie.gif" alt="" width="34" height="28"/>','<img src="'+this.sImgsDir+'sravnit-sportivnoe-pitanie-v.gif" alt="" width="34" height="28"/>'];
		oCompare.createBlockLinks();
		fadeOpacity.addRule('oisBCompare',0.1,1,50);
	}
}
ISCompare.prototype.createBlockLinks = function(){
	var s='<div id="oCompareLinks" onmouseout="'+this.nameOfClass+'.showCompareLinks()" class="unvis"><div><div><div>'
	+'<img src="'+this.sImgsDir+'sportivnoe-pitanie-sravnenie.gif" alt="" width="13" height="25" style=""/>'
	+'<a id="oCompareLinksOper" onmouseout="'+this.nameOfClass+'.noBub()" onmousemove="'+this.nameOfClass+'.hideDelayedCompareLinks()" onclick="'+this.nameOfClass+'.operateCompareLinks()"></a>'
	+'<a id="oCompareLinksTable" onmouseout="'+this.nameOfClass+'.noBub()" onmousemove="'+this.nameOfClass+'.hideDelayedCompareLinks()" onclick="'+this.nameOfClass+'.goCompare()" class="last"></a>'
	+'</div></div></div></div>';
	D.writeln(s);
}
ISCompare.prototype.createLink = function(id, name){
	if(this.allowBrowser){
		var sImg=this.sImgs[ (this.checkCompareACIds(id)>-1?1:0) ];
		var s='<div class="oCompareLink"><a href="" onmouseover="oCompare.showCompareLinks(1,'+ id +',\''+ name +'\',this)" onclick="noRet()">'+ sImg +'</a></div>';
		D.writeln(s);
	}
}
ISCompare.prototype.goCompare=function(){
	var url=this.aCIds.join("|");
	if(this.aCIds.length < this.iMax) url+="|";
	/*this.aCIds=[]; this.cooSet();*/
	D.location="http://www.ironsport.com.ua/index.php?creatine=product_compare&products_ids="+url;
	event.returnValue=false;
}
ISCompare.prototype.noBub = function(){
	event.cancelBubble=true;
}
ISCompare.prototype.cooGet = function(){
	var nEQ=this.cooName+"=";
	var ca=D.cookie.split(";");
	for(var i=0;i<ca.length;i++) {
		var c=ca[i];
		while(c.charAt(0)==" ") c=c.substring(1,c.length);
		if(c.indexOf(nEQ)==0){
			var r=c.substring(nEQ.length,c.length);
			return (r=='undefined') ? null : r;
		}
	}
	return null;
}
ISCompare.prototype.cooSet = function(s){
	D.cookie=this.cooName+"="+ (typeof(s)=='undefined' ? this.aCIds.join("|") : s);
}
ISCompare.prototype.setImg = function(f){
	this.oCL.firstChild.src=this.sImgsDir+"sravnit-sportivnoe-pitanie"+(f?".gif":"-v.gif");
}
ISCompare.prototype.operateCompareLinks = function(){
	if(this.oCId){
		var src=this.sImgsDir+"sravnit-sportivnoe-pitanie";
		var i=this.checkCompareACIds(this.oCId);
		if(i>-1){
			var a=[];
			var len=this.aCIds.length;
			for(var k=0; k<len; k++)
				if(i!=k) a[a.length]=this.aCIds[k];
			this.aCIds=a;
			this.setImg(1);
		}else{
			this.aCIds[this.aCIds.length]=this.oCId;
			this.aCNames[this.aCNames.length]=this.oCName;
			this.setImg(0);
		}
		this.cooSet();
	}
	event.returnValue=false;
	this.showCompareLinks();
}
ISCompare.prototype.checkCompareACIds = function(id){
	var len=this.aCIds.length;
	for(var i=0;i<len;i++)
		if(this.aCIds[i]==id) return i;
	return -1;
}
ISCompare.prototype.$ = function(s){
	return D.getElementById(s);
}
ISCompare.prototype.showCompareLinks = function(toVis, id, name, o){
	if(typeof(toVis)=="undefined") toVis=0;
	var oC=ISCompare.prototype.$("oCompareLinks");
	if(toVis){
		var oCO=ISCompare.prototype.$("oCompareLinksOper");
		var oCT=ISCompare.prototype.$("oCompareLinksTable");
		this.oCId=id;
		this.oCName=name;
		this.oCL=o;
		var sInfo="";
		if(this.checkCompareACIds(id) > -1){
			oCO.style.display="";
			oCO.innerHTML='<span class="del"><b>[-] Удалить</b> '+name+' из таблицы сравнения</span>';
		}else{
			if(this.aCIds.length<this.iMax){
				oCO.style.display="";
				oCO.innerHTML='<b>[+] Добавить</b> '+name+' для сравнения';
			}else{
				oCO.style.display="none";
				oCO.innerHTML="";
				sInfo='<br/><br/><span>Достигнут максимум ('+this.iMax+' шт.) товаров для сравнения</span>';
			}
		}
		if(this.aCIds.length){
			oCT.innerHTML="<b>Просмотреть</b> таблицу сравнения"+sInfo;
			oCT.style.padding=oCT.style.fontSize=oCT.style.height=oCT.style.overflow="";
		}else{
			oCT.innerText="";
			oCT.style.padding=oCT.style.fontSize=oCT.style.height="0";
			oCT.style.overflow="hidden";
		}
		var aPos=getPos(this.oCL);
		oC.style.left=(aPos[0]-10)+"px";
		var iTopShift=22;
		if(this.browser=='IE' && this.browserVer>=8){
			iTopShift+=30;
		}else if(this.browser=='NS'){
			iTopShift+=20;
		}
		oC.style.top=(aPos[1]-iTopShift)+"px";
		if(this.browser=='IE'){
			oC.className="vis";
			this.oCVis=1;
		}else{
			clearTimeout(this.iSTOC0);
			clearTimeout(this.iSTOC1);
			clearTimeout(this.iSTOC2);
			this.iSTOC2=setTimeout(function(){this.oCVis=1;oC.className="vis"},100);
			fadeOpacity(oC.id,'oisBCompare');
		}
		this.hideDelayedCompareLinks();
	}else{
		if(this.browser=='IE'){
			oC.className="unvis";
			this.oCVis=0;
		}else{
			fadeOpacity.back(oC.id);
			clearTimeout(this.iSTOC0);
			clearTimeout(this.iSTOC1);
			clearTimeout(this.iSTOC2);
			this.iSTOC1=setTimeout(function(){oC.className="unvis"},1000);
			this.oCVis=0;
		}
	}
}
ISCompare.prototype.hideDelayedCompareLinks = function(){
	clearTimeout(this.iSTOC0);
	this.iSTOC0=setTimeout(this.nameOfClass+".showCompareLinks()",1500);
}
/*ISCompare.prototype.add2ACompare = function(a){
	try{ var c=this.cooGet(); a.href+=c+'|'; }catch(e){}
}*/


//=================
//- ISTicker -
function ISTicker(id){
	this.e=$(id);
	this.content=this.e.innerHTML;
	this.toLeft=false;
	this.speed=2;
	this.style="font-family:Arial;font-size:12px;color:#333";
	this.paused=false;
	this.ticker_start = function(){
		var tickerSupported = false;
		var width=520; //this.e.style.width;
		var img="<img src='http://www.ironsport.com.ua/includes/templates/iron_sport/images/spacer.gif' width="+width+" height=0 border=0>";
		if (navigator.userAgent.indexOf("Firefox")!=-1 || navigator.userAgent.indexOf("Safari")!=-1) {	// Firefox
			this.e.innerHTML = "<TABLE cellspacing='0' cellpadding='0' width='100%'><TR><TD style='white-space:nowrap' nowrap='nowrap'>"+img+"<SPAN style='"+this.style+"' ID='TICKER_BODY' width='100%'>&nbsp;</SPAN>"+img+"</TD></TR></TABLE>";
			/*-*/if(navigator.userAgent.indexOf("Firefox")!=-1){	this.e.style.marginTop="-13px";	}
			tickerSupported = true;
		} else if (/*navigator.userAgent.indexOf("MSIE")!=-1 ||*/ navigator.userAgent.indexOf("Opera")!=-1) {	// IE
			this.e.innerHTML = "<DIV nowrap='nowrap' style='width:100%'>"+img+"<SPAN style='"+this.style+"' ID='TICKER_BODY' width='100%'></SPAN>"+img+"</DIV>";
			tickerSupported = true;
		}
		if(!tickerSupported) this.e.outerHTML = ""; else {
			this.e.scrollLeft = this.toLeft ? this.e.scrollWidth - this.e.offsetWidth : 0;
			$("TICKER_BODY").innerHTML = this.content;
			this.e.style.display="block";
			this.ticker_tick();
		}
		this.e.onmouseover=function(){ oISTicker.paused=true; }
		this.e.onmouseout=function(){ oISTicker.paused=false; }
	}
	this.ticker_tick = function(){
		if(!this.paused) this.e.scrollLeft += this.speed * (this.toLeft ? -1 : 1);
		if(this.toLeft && this.e.scrollLeft <= 0) this.e.scrollLeft = this.e.scrollWidth - this.e.offsetWidth;
		if(!this.toLeft && this.e.scrollLeft >= this.e.scrollWidth - this.e.offsetWidth) this.e.scrollLeft = 0;
		window.setTimeout('oISTicker.ticker_tick()', 50);
	}
}


//=================
/* http://www.tigir.com/opacity.htm
Установка прозрачности
Пример: setElementOpacity(document.body, 0.5); //сделать прозрачным на половину
*/	
function setElementOpacity(oElem, nOpacity){
	var p = getOpacityProperty();
	(setElementOpacity = p=="filter"?new Function('oElem','nOpacity','nOpacity*=100; var oAlpha=oElem.filters["DXImageTransform.Microsoft.alpha"] || oElem.filters.alpha;	if (oAlpha) oAlpha.opacity = nOpacity; else oElem.style.filter += "progid:DXImageTransform.Microsoft.Alpha(opacity="+nOpacity+")";'):p?new Function('oElem','nOpacity','oElem.style.'+p+'=nOpacity;'):new Function)(oElem, nOpacity);
}
// возвращает свойство которое используется для смены прозрачности или undefined
function getOpacityProperty(){
	var p;
	if (typeof document.body.style.opacity=='string') p='opacity';
	else if (typeof document.body.style.MozOpacity=='string') p='MozOpacity';
	else if (typeof document.body.style.KhtmlOpacity=='string') p='KhtmlOpacity';
	else if (document.body.filters && navigator.appVersion.match(/MSIE ([\d.]+);/)[1]>=5.5) p='filter';
	return (getOpacityProperty=new Function("return '"+p+"';"))();
}
/* плавное изменения прозрачности:
1) fadeOpacity.addRule('opacityRule1', 1, 0.5, 30); //вначале создаем правило, задаем имя правила, начальную прозрачность и конечную, необязательный параметр задержки, влийяющий на скорость смены прозрачности
2) fadeOpacity('elemID', 'opacityRule1'); // выполнить плавную смену прозрачности элемента с id равным elemID, по правилу opacityRule1
3) fadeOpacity.back('elemID'); //вернуться в исходное сотояние прозрачности
*/
function fadeOpacity(sElemId, sRuleName, bBackward){
	var elem=document.getElementById(sElemId);
	if(!elem || !getOpacityProperty() || !fadeOpacity.aRules[sRuleName]) return;
	var rule=fadeOpacity.aRules[sRuleName];
	var nOpacity=rule.nStartOpacity;
	if(fadeOpacity.aProc[sElemId]) {clearInterval(fadeOpacity.aProc[sElemId].tId); nOpacity=fadeOpacity.aProc[sElemId].nOpacity;}
	if((nOpacity==rule.nStartOpacity && bBackward) || (nOpacity==rule.nFinishOpacity && !bBackward)) return;
	fadeOpacity.aProc[sElemId]={'nOpacity':nOpacity,'tId':setInterval('fadeOpacity.run("'+sElemId+'")',fadeOpacity.aRules[sRuleName].nDalay),'sRuleName':sRuleName,'bBackward':Boolean(bBackward)};
}
fadeOpacity.addRule = function(sRuleName, nStartOpacity, nFinishOpacity, nDalay){fadeOpacity.aRules[sRuleName]={'nStartOpacity':nStartOpacity,'nFinishOpacity':nFinishOpacity,'nDalay':(nDalay || 30),'nDSign':(nFinishOpacity-nStartOpacity > 0?1:-1)};};
fadeOpacity.back = function(sElemId){fadeOpacity(sElemId,fadeOpacity.aProc[sElemId].sRuleName,true);};
fadeOpacity.run = function(sElemId){
	var proc = fadeOpacity.aProc[sElemId];
	var rule = fadeOpacity.aRules[proc.sRuleName];
	var nSteps = B=='IE' ? 8 :10;//-
	proc.nOpacity = Math.round(( proc.nOpacity + .1*rule.nDSign*(proc.bBackward?-1:1) )*nSteps)/nSteps;
	setElementOpacity(document.getElementById(sElemId), proc.nOpacity);
	if(proc.nOpacity==rule.nStartOpacity || proc.nOpacity==rule.nFinishOpacity) clearInterval(fadeOpacity.aProc[sElemId].tId);
}
fadeOpacity.aProc={};
fadeOpacity.aRules={};

//===
function ISShowPhoto(){
	this.f=0;
	this.iT0, this.iT1, this.iT2;
	fadeOpacity.addRule('oisBShowPhoto',0,1,40);
	this.run = function(e,f){
		var eI=$('isShowPhoto');
		if(e){
			if(!this.f){
				eI.src=e.src;
				var a=getPos(e);
				fadeOpacity('isShowPhoto','oisBShowPhoto');
				clearTimeout(this.iT0); clearTimeout(this.iT1); clearTimeout(this.iT2);
				this.iT0=setTimeout(function(){eI.style.left=(a[0]-90)+'px'; eI.style.top=(a[1]-90)+'px'; this.f=1}, 100);
			}
		}else{
			fadeOpacity.back('isShowPhoto');
			clearTimeout(this.iT0); clearTimeout(this.iT1); clearTimeout(this.iT2);
			this.iT1=setTimeout(function(){eI.style.left='-9999px'; eI.style.top='-9999px'}, 1000);
			this.iT2=setTimeout(function(){this.f=0}, 100);
		}
	}
}
var oisShowPhoto = new ISShowPhoto();
