
function defineOs(){
	var os=navigator.userAgent;
	if(os.indexOf("Mac")!=-1){
		os="Mac";
	} else {
		os="Win";
	}
	return os;
};
function defineBrowser(){
	var browser="None";
	if(navigator.appName.indexOf("Netscape")>=0&&parseFloat(navigator.appVersion)>=4){
		browser="NS4";version=4;
	}
	if(document.getElementById){
		browser="NS6";
		if(navigator.userAgent.indexOf("6.01")!=-1||navigator.userAgent.indexOf("6.0")!=-1){
			version=6;}
		else{
			version=6.1;
		}
	}
	if(document.all){
		if(document.getElementById){
			version=5;
		} else {
			version=4;
		}
		browser="IE";
	}
	if(navigator.userAgent.indexOf("Opera")!=-1){
		browser="Opera";
		if(navigator.userAgent.indexOf("7.")!=-1){
			version=7;
		} else {
			version=6;
		}
	}
	return browser;
};
function invert(element,show){
	if(browser=="NS4"){
		if(document.layers[element]!=undefined){
			if(show){
				document.layers[element].visibility="show";
			} else {
				document.layers[element].visibility="hide";
			}
		}
	}
	if(browser=="IE"){
		if(document.all[element]!=null){
			if(show){
				document.all[element].style.visibility="visible";
			} else {
				document.all[element].style.visibility="hidden";
			}
		}
	}
	if(browser=="NS6"||browser=="Opera"){
		if(document.getElementById(element)!=null){
			if(show){
				document.getElementById(element).style.visibility="visible";
			} else {
				document.getElementById(element).style.visibility="hidden";
			}
		}
	}
};

function posLeft(element,left,parent){
	if(browser=="NS4"){
		if(arguments.length>=3){
			document.layers[parent].document.layers[element].left=left;
		} else {
			document.layers[element].left=left;
		}
	}
	if(browser=="IE"){
		document.all[element].style.left=left+'px';
	}
	if(browser=="NS6"||browser=="Opera"){
		document.getElementById(element).style.left=left+'px';
	}
};

function offLeft(element,parent){
	if(browser=="NS4"){
		if(arguments.length>=2){
			return(document.layers[parent].document.layers[element].pageX);
		} else {
			return(document.layers[element].pageX);
		}
	}
	if(browser=="IE"){
		return(document.all[element].offsetLeft);
	}
	if(browser=="NS6"){
		return(document.getElementById(element).offsetLeft);
	}
	if(browser=="Opera"){
		if(version==7){
			return(document.getElementById(element).offsetLeft);
		} else {
			return(document.getElementById(element).style.pixelLeft);
		}
	}
};
function Topstyle(element,top,parent){
	if(browser=="NS4"){
		if(arguments.length>=3){
			document.layers[parent].document.layers[element].top=top;
		} else {
			document.layers[element].top=top;
		}
	}
	if(browser=="IE"){
		document.all[element].style.top=top+'px';
	}
	if(browser=="NS6"||browser=="Opera"){
		document.getElementById(element).style.top=top+'px';
	}
};
function offTop(element,parent){
	if(browser=="NS4"){
		if(arguments.length>=2){
			return(document.layers[parent].document.layers[element].pageY);
		} else {
			return(document.layers[element].pageY);
		}
	}
	if(browser=="IE"){
		return(document.all[element].offsetTop);
	}
	if(browser=="NS6"){
		return(document.getElementById(element).offsetTop);
	}
	if(browser=="Opera"){
		if(version==7){
			return(document.getElementById(element).offsetTop);
		} else {
			return(document.getElementById(element).style.pixelTop);
		}
	}
};

function offHeight(element,parent){
	if(browser=="NS4"){
		if(arguments.length>=2){
			return(document.layers[parent].document.layers[element].clip.height);
		} else {
			return(document.layers[element].clip.height);
		}
	}
	if(browser=="IE"){
		return(document.all[element].offsetHeight);
	}
	if(browser=="NS6"){
		return(document.getElementById(element).offsetHeight);
	}
	if(browser=="Opera"){
		if(version==7){
			return(document.getElementById(element).offsetHeight);
		} else {
			return(document.getElementById(element).style.pixelHeight);
		}
	}
};

function clipDraw (element,top,right,bottom,left){
 if(browser=="NS4"){
  document.layers[element].clip.top=top;
  document.layers[element].clip.right=right;
  document.layers[element].clip.height=bottom-top;
  document.layers[element].clip.left=left;
}
 if(browser=="IE"||browser=="NS6"||browser=="Opera"){
  document.getElementById(element).style.clip='rect('+top+'px, '+right+'px, '+bottom+'px, '+left+'px)';
 }
}
browser=defineBrowser();
os=defineOs();

function Picture(){
 bool=1;
 
 this.y_offset=0;
 this.x_offset=0;
 this.name='pictur';
 this.heightArray=new Array(100);
 this.currentspeed=50;
 this.curTopItem=1;
 this.numItems=0;
 this.stop=true;
 this.x=0;
 this.y=0;
 this.timeOutArray=new Array(30);
 this.tiac=0;
 this.add=AddPictureItem;
 this.display=function(){
  if(browser=="NS4"){
    document.write('<ilayer id="pictur" id="pictur" width="'+this.width+'" height="'+this.height+'">');
    document.write('</ilayer><br>');
  }
  if(browser=="IE"||browser=="NS6"||browser=="Opera"){document.write('<div id="pictur" style="position:relative; width:'+this.width+'px; height:'+this.height+'px; z-index:2" onmouseover="if (pictures.mousepause){stopmove();}" onmouseout="if (pictures.mousepause){pictures.timeOutArray[pictures.tiac++] = setTimeout(\'startmove()\', 50);}"></div>');
  }
  setScroll(1);
 };
};
function AddPictureItem(text){
  this.numItems++;
  if(browser=="NS4"){document.writeln('<layer id="picturitm'+this.numItems+'" visibility="hide" width="'+this.width+'">');
    if(arguments.length>=1){
      document.writeln(text);document.writeln('</layer>');
    }
  }
  if(browser=="IE"||browser=="NS6"||browser=="Opera"){
    document.writeln('<div id="picturitm'+this.numItems+'" style="visibility:hidden;position:absolute;width:'+this.width+'px;z-index:3" onmouseover="if (pictures.mousepause){stopmove();}"  onmouseout="if (pictures.mousepause){pictures.timeOutArray[pictures.tiac++] = setTimeout(\'startmove()\', 50);}">');
    if(arguments.length>=1){document.writeln(text);document.writeln('</div>');}
  }
};
function LoadPicture(){
  if(os=="Mac"&&browser=="IE"){
    pictures.y_offset=parseInt(document.body.topMargin);pictures.x_offset=parseInt(document.body.leftMargin);
  } 
  if(!(browser=="Opera"&&version==6)) setTimeout('operaTimeOut()',50);
};
function operaTimeOut(){
  pictures.y=offTop('pictur');
  pictures.x=offLeft('pictur');
  if(bool==0){
    return;
  } 
  pictures.curTopItem=1;
  var name='picturitm';
  var y=pictures.y-1;
  var h;
  for(var i=pictures.curTopItem;i<=pictures.numItems;i++){
    Topstyle(name+i,y);
    posLeft(name+i,pictures.x+pictures.x_offset);
    h=offHeight(name+i);
    pictures.heightArray[i]=h;
    if(y<pictures.y+pictures.y_offset||y+h>pictures.y+pictures.y_offset+pictures.height){
      clipDraw(name+i,Math.max(0,pictures.y+pictures.y_offset-y),pictures.width,Math.min(pictures.y+pictures.y_offset+pictures.height-y,h),0)
    }
    y+=h+pictures.spacer;
    invert(name+i,true);
  }
  
  if(browser=="Opera"&&version!=7){
    return;
  }
  if(pictures.stop){
    pictures.stop=false;
    pictures.currentspeed=pictures.scrollspeed;
    if(scrollActive!=0){
           setTimeout('mainProc()',pictures.pausedelay);
    }
  }
};
function getHeight(element,index){
   if(browser=="NS4"){
     return(pictures.heightArray[index]);
   }
   if(browser=="IE"){
     return(document.all[element].offsetHeight);
   }
   if(browser=="NS6"){
     return document.getElementById(element).offsetHeight;
   }
   if(browser=="Opera"){
     if(version==7){
       return(document.getElementById(element).offsetHeight);
     } else {
       return(document.getElementById(element).style.pixelHeight);
     }
   }
};
function setScroll(){
   if(arguments.length==1){
      scrollActive=1;
   }
};
function mainProc(){
  var y=0;
  var i;
  var name='picturitm';
  var cur_name=name+pictures.curTopItem;
  if(offTop(cur_name)+getHeight(cur_name,pictures.curTopItem)<pictures.y){
    Topstyle(cur_name,-800);
    if(pictures.curTopItem==pictures.numItems){
      pictures.curTopItem=1;
    } else {
      pictures.curTopItem++;
    }
    cur_name=name+pictures.curTopItem;
  }
  y=offTop(cur_name)+pictures.y_offset;
  pictures.currentspeed=pictures.scrollspeed;
  for(i=pictures.curTopItem;i<=pictures.numItems;i++){
     y=mainLoop(name+i,i,y);
  }
  for(i=1;i<pictures.curTopItem;i++){
     y=mainLoop(name+i,i,y);
  }
  if(!pictures.stop){
    pictures.timeOutArray[pictures.tiac++]=setTimeout('mainProc()',pictures.currentspeed);
  }
};
function mainLoop(cur_name,i,y){
   if(y<pictures.height+pictures.y){
     var item_y=offTop(cur_name)+pictures.y_offset;
     var item_h=getHeight(cur_name,i);
     if(item_y==pictures.y&&pictures.pausedelay>pictures.scrollspeed){
       pictures.currentspeed=pictures.pausedelay;
     }
     if(item_y>-800){
       Topstyle(cur_name,item_y-1);
     } else {
       Topstyle(cur_name,y);
     }
     if(item_y<pictures.y+pictures.y_offset||item_y+item_h>pictures.y+pictures.y_offset+pictures.height){
       clipDraw(cur_name,Math.max(0,pictures.y+pictures.y_offset-item_y),pictures.width,Math.min(pictures.y+pictures.y_offset+pictures.height-item_y,item_h),0);
     }
     y+=item_h+pictures.spacer;
     invert(cur_name,true);
   } else {
     Topstyle(cur_name,-800);
   }
   return y;
};
scrollActive=0;
bool=0;


function stopmove(){
  for(var i=0;i<pictures.tiac;i++){
    clearTimeout(pictures.timeOutArray[i]);
  }
  pictures.tiac=0;
  pictures.stop=true;
};
function startmove(){
  if(pictures.stop){
     for(var i=0;i<pictures.tiac;i++){
       clearTimeout(pictures.timeOutArray[i]);
     }
     pictures.tiac=0;
     pictures.stop=false;
     pictures.currentspeed=pictures.scrollspeed;
     mainProc();
  }
};
function showpicture(filenum, wid, hei){
	if(browser=="NS6"||browser=="Opera"){
		document.getElementById('picture_b').style.backgroundImage="url('graph/samoetiket/etiket1"+filenum+"_b.gif')";

	} else{
         	document.all.picture_b.style.backgroundImage="url('graph/samoetiket/etiket1"+filenum+"_b.gif')";
	}
	numpic=filenum;
}
function initPictures(){
	pictures = new Picture();
	pictures.height = 300;
	pictures.width = 72;
	pictures.pausedelay = 5;
	pictures.spacer = 0;
	pictures.scrollspeed = 100;
	pictures.mousepause = true;
	pictures.add('<a href="" onclick="showpicture('+"'1','232','232');return false"+'"><img border="1" alt="Самоклеящаяся этикетка '+"'Русский Хлеб'"+'. Нажмите для просмотра" src="graph/samoetiket/etiket1.gif" height="64" width="64"></a><div class="pereg"><img src="graph/spacer.gif" height="5"></div></a>');
	pictures.add('<a href="" onclick="showpicture('+"'2','228','346');return false"+'"><img border="1" alt="Самоклеящаяся этикетка '+"'Мясомолторг'"+'. Нажмите для просмотра" src="graph/samoetiket/etiket2.gif" height="64" width="64"></a><div class="pereg"><img src="graph/spacer.gif" height="5"></div></a>');
	pictures.add('<a href="" onclick="showpicture('+"'3','212','352');return false"+'"><img border="1" alt="Самоклеящаяся этикетка '+"'Хелиос'"+'. Нажмите для просмотра" src="graph/samoetiket/etiket3.jpg" height="64" width="64"></a><div class="pereg"><img src="graph/spacer.gif" height="5"></div></a>');
	pictures.add('<a href="" onclick="showpicture('+"'4','192','170');return false"+'"><img border="1" alt="Самоклеящаяся этикетка '+"'ООО Аргилашпродукт'"+'. Нажмите для просмотра" src="graph/samoetiket/etiket4.gif" height="64" width="64"></a><div class="pereg"><img src="graph/spacer.gif" height="5"></div></a>');
	pictures.add('<a href="" onclick="showpicture('+"'5','213','299');return false"+'"><img border="1" alt="Самоклеящаяся этикетка '+"'Коровье молоко'"+'. Нажмите для просмотра" src="graph/samoetiket/etiket5.gif" height="64" width="64"></a><div class="pereg"><img src="graph/spacer.gif" height="5"></div></a>');
	pictures.add('<a href="" onclick="showpicture('+"'6','200','280');return false"+'"><img border="1" alt="Самоклеящаяся этикетка '+"'ТД Чикен-Плюс'"+'. Нажмите для просмотра" src="graph/samoetiket/etiket6.gif" height="64" width="64"></a><div class="pereg"><img src="graph/spacer.gif" height="5"></div></a>');
	pictures.add('<a href="" onclick="showpicture('+"'7','193','150');return false"+'"><img border="1" alt="Самоклеящаяся этикетка '+"'Минмлечсоюз'"+'. Нажмите для просмотра" src="graph/samoetiket/etiket7.gif" height="64" width="64"></a><div class="pereg"><img src="graph/spacer.gif" height="5"></div></a>');
	pictures.display();
	onload = LoadPicture;
	onresize = LoadPicture;
	
}
var numpic=1;
function prevpicture(){
	if (numpic==1){numpic=8}
	numpic--;
	if(browser=="NS6"||browser=="Opera"){
		document.getElementById('picture_b').style.backgroundImage="url('graph/samoetiket/etiket1"+numpic+"_b.gif')";

	} else{
         	document.all.picture_b.style.backgroundImage="url('graph/samoetiket/etiket1"+numpic+"_b.gif')";
	}
}
function nextpicture(){
	if (numpic==7){numpic=0}
	numpic++;
	if(browser=="NS6"||browser=="Opera"){
		document.getElementById('picture_b').style.backgroundImage="url('graph/samoetiket/etiket1"+numpic+"_b.gif')";

	} else{
         	document.all.picture_b.style.backgroundImage="url('graph/samoetiket/etiket1"+numpic+"_b.gif')";
	}
}
