
//DeltaX=325
//DeltaY=326
if( typeof DeltaX != 'number' )DeltaX=310
if( typeof DeltaY != 'number' )DeltaY=210

ti=document.getElementById('SameImage');
ti2=document.getElementById('SameImage2');
tv=document.getElementById('image_viewer');
np=document.getElementById('N_Panel_Image');
tnp=document.getElementById('N_Panel');
NPtitle=document.getElementById('N_Panel_Title');

ymax=document.documentElement.offsetHeight-DeltaY
xmax=document.documentElement.offsetWidth-DeltaX


//			<div id="N_Panel">
//				<div id="N_Panel_Title"></div>
//				<div id="N_Panel_Image"></div>
//			</div>

tv.style.height=ymax
tv.style.width=xmax
ImageIndex=1;


//Создаём массив картинок
MaxPage=20;
ImgArray = new Array()
for(i=1;i<=MaxPage;i++){
	ImgArray[i] = new Array(960,630)
	ImgArray[i][2] = SiteUrl+'images/presentation/images_'+(i)+'.jpg'
	ImgArray[i][3] = SiteUrl+'images/presentation/small/images_'+i+'.jpg'
	ImgArray[i][4] = SiteUrl+'images/presentation/smallgrey/images_'+i+'.jpg'
}

//корректируем окно вывода

ImgCor=ImgArray[1][0]/ImgArray[1][1]
PageCor=xmax/ymax

//в зависимости от соотношения сторон делаем корректировку картинки
if(ImgCor>PageCor){
	ymax=xmax/ImgCor
}else{
	xmax=ymax*ImgCor
}
ti.style.width=xmax
ti.style.height=ymax
ti2.style.width=xmax
ti2.style.height=ymax
tv.style.width=xmax

sImgWidth=152
sImgHeight=100
nbImgWidth=46
nbImgHeight=130
npHsize=109

tnp.style.width=xmax
tnp.style.height=ymax


//np.style.marginTop=ymax-npHsize-npBottomSize-50
np.style.height=npHsize



sImgCount=(xmax-40-nbImgWidth*2)/(sImgWidth+2+3+1)
sImgCount2=Math.floor(sImgCount/2)
sImgCount=Math.floor(sImgCount)
np.style.width=(sImgWidth+2+3)*sImgCount+nbImgWidth*2+20

i=10;
LoadTransaction=0;
function generateImgNavigation(){
	SlideCount=ImageIndex-sImgCount2;

	if(ImageIndex<=sImgCount2)SlideCount=1
	if(ImageIndex>(MaxPage-sImgCount2))SlideCount=MaxPage-sImgCount+1


	np.innerHTML='';
	//np.innerHTML='<a href="" class="LRbutton" onClick="changeImgage(1);return false;"><img id="imgleft" src="'+SiteUrl+'images/4/StartButton.gif" width="63" height="100" alt="|<" border="0"></a>';
	np.innerHTML+='<a href="" class="LRbutton" onClick="imageList(-1);"><img onMouseDown="this.src=\''+SiteUrl+'images/4/LeftButtonP.gif\';"  id="imgleft" src="'+SiteUrl+'images/4/LeftButton.gif" width="44" height="100" alt="<" border="0"></a>';

	for(i=SlideCount;i<(SlideCount+sImgCount);i++){

		if(i!=ImageIndex)np.innerHTML+='<a  href="" onClick="changeImgage('+i+');return false;"><img id="image_'+i+'" src="'+ImgArray[i][3]+'" alt="Слайд '+i+'" width="152" height="100"  title="Слайд '+i+'"></a>';
		else np.innerHTML+='<a  href="" onClick="changeImgage('+i+');return false;"><img id="image_'+i+'" src="'+ImgArray[i][3]+'" alt="Слайд '+i+'" width="160" height="105"  title="Слайд '+i+'"></a>'
	}
	np.innerHTML+=' <a href="" class="LRbutton"  onClick="imageList(1);return false;"><img onMouseDown="this.src=\''+SiteUrl+'images/4/RightButtonP.gif\';"   id="imgright" src="'+SiteUrl+'images/4/RightButton.gif" width="44" height="100"  alt=">" border="0"></a>';
	//np.innerHTML+=' <a href="" class="LRbutton"  onClick="changeImgage('+MaxPage+');return false;"><img id="imgright" src="'+SiteUrl+'images/4/EndButton.gif" width="63" height="100" alt=">|"border="0"></a>';

	$("#NavigationPanel").animate({opacity: "1"}, 500)


	//NPanelOn()
	NPtitle.innerHTML="Слайд "+ImageIndex
}



function changeImgage(i){
	if(LoadTransaction!=1){
		$("#NavigationPanel").animate({opacity: "1"}, 0)
		LoadTransaction=1;
		aTime=300;
		if(ImageIndex!=0)$("#SameImage2").animate({opacity: "1"}, aTime)
		SmallImage=document.getElementById('image_'+i)
		if(SmallImage)SmallImage.src=ImgArray[i][4]
		setTimeout('ti.src="'+ImgArray[i][2]+'"',aTime);
 	    ImageIndex=i;
 	    //generateImgNavigation()
 	 }
}

function open3Image(){
	//ti.style.display='block'
	//ti2.style.display='block'
	aTime=500;
	if(ImageIndex!=0){
		$("#SameImage").animate({opacity: "1"}, aTime)
	}else{
		$("#SameImage").animate({opacity: "1"}, 0)
	}
	$("#SameImage2").animate({opacity: "0"}, aTime)
	setTimeout('ti2.src="'+ti.src+'"',aTime+100);
}
function open2Image(){
	aTime=100;
	i=ImageIndex
	LoadTransaction=0;
	NPanelOn()
 	generateImgNavigation()
}

function imageList(x){
	p=ImageIndex+x;
	if(p<1)p=1;
	if(p>=MaxPage)p=MaxPage
	changeImgage(p)

}
$("#SameImage").animate({opacity: "0"}, 0)
$("#SameImage2").animate({opacity: "0"}, 0)
$("#NavigationPanel").animate({opacity: "0"}, 0)

imageList(0)

generateImgNavigation()

function newTimer(x){
    if(x==1){
    	NPanelOn();
    }
    if(x==0){
    	NPanelOff();
    }
}
function NPanelOn(){
	$("#N_Panel").animate({opacity: "1"}, 500)
	if( typeof TimerID == 'number' )clearTimeout(TimerID)
	TimerID=setTimeout('NPanelOff()',2000)
}
function NPanelOff(){	if( typeof TimerID == 'number' )clearTimeout(TimerID)
	$("#N_Panel").animate({opacity: "0"}, 500)
}




