function onmenu(image){
 var x=document.getElementById(image);
 var a=x.src;
 a=a.replace('.gif', '_.gif');
 a=a.replace('.jpg', '_.jpg');
 x.src=a;
 
}
 
function outmenu(image){
 var x=document.getElementById(image);
 var a=x.src;
 a=a.replace('_.gif', '.gif');
 a=a.replace('_.jpg', '.jpg');
 x.src=a;
 
}

/*****************************
           PopupWindow
******************************/

function getDims(winWidth, winHeight){
	var dims = new Object();
	dims.widthStr = '';
	dims.heightStr = '';
	dims.scrollbars = false;
	if (winWidth){
		dims.width = winWidth;
		if (screen.width < dims.width + 50){
			dims.width = screen.width - 50;
			dims.scrollbars = true;
		}
		dims.widthStr = ',width=' + dims.width;
	}
	
	if (winHeight){
		dims.height = winHeight;
		if (screen.height < dims.height + 100){
			dims.height = screen.height - 100;
			dims.scrollbars = true;
		}
		dims.heightStr = ',height=' + dims.height;
	}
	dims.scrollbarsStr = (dims.scrollbars)? ',scrollbars=yes' : ',scrollbars=no';
	dims.posX = Math.round((screen.width - dims.width) / 2);
	dims.posY = Math.round((screen.height - winHeight) / 2);
	dims.posCode = (document.all)? ',left=' + dims.posX + ',top=' + dims.posY : ',screenX=' + dims.posX + ',screenY=' + dims.posY;
	return dims;
}

function popupImg(imgSrc, winName, imgWidth, imgHeight, winTitle){
	winWidth = (imgWidth)? imgWidth + 0 : null;
	winHeight = (imgHeight)? imgHeight + 0 : null;
	var dims = getDims(winWidth, winHeight);
	var popupwin = window.open('', winName, 'menubar=no,toolbar=no,resizable=yes,status=yes' + dims.scrollbarsStr + dims.widthStr + dims.heightStr + dims.posCode);
	popupwin.resizeTo(dims.width + 12, dims.height + 83)

if (popupwin){
		popupwin.document.open();
		popupwin.document.write('<html><head><title>' + winTitle + '</title></head><body bgcolor="white" style="margin: 0px 0px; padding: 0px;">')
		popupwin.document.write('<img src="' + imgSrc + '" width="' + imgWidth + '" height="' + imgHeight + '" />')
		popupwin.document.write('</body></html>')
		popupwin.document.close();
		popupwin.focus();
	}
	return false;
}



function box_cross(box_1, box_2, maxbox){


if (box_2<1001) { 

	box_2 = maxbox;
	open_box = maxbox;
}

if (box_2>maxbox) { 

	box_2 = 1001;
	open_box = 1001;
}

var scroll = document.body.scrollTop + document.documentElement.scrollTop;

var box_to_hide = document.getElementById(box_1);
var box_to_show = document.getElementById(box_2);
var main = document.getElementById('main_box');

    box_to_hide.style.opacity = 1; 
    box_to_hide.style.filter='alpha(opacity=100)'; 
    box_to_show.style.opacity = 0; 
    box_to_show.style.filter='alpha(opacity=0)'; 

    box_to_show.style.left = (getClientWidth()-900)/2 - 100  +'px';
    box_to_show.style.top = (getClientHeight()-729)/2 - 100 + scroll+'px';


box_to_show.style.display = 'block';

var from = 0; // Начальная координата X
var to = 1; // Конечная координата X
var duration = 500; // Длительность - 1 секунда
var start = new Date().getTime(); // Время старта
 
setTimeout(function() {
    var now = (new Date().getTime()) - start; // Текущее время
    var progress = now / duration; // Прогресс анимации

    var op = (to - from) * progress + from;

if (op < 0) op=0;
if (op > 1) op=1;

    box_to_hide.style.opacity = 1-op; 
    box_to_hide.style.filter='alpha(opacity='+(1-op)*100+')';  
    box_to_show.style.opacity = op; 
    box_to_show.style.filter='alpha(opacity='+op*100+')'; 
 
    if (progress < 1) { // Если анимация не закончилась, продолжаем
        setTimeout(arguments.callee, 10);
}
else{
    box_to_show.style.filter='none'; 
    box_to_hide.style.filter='none'; 
    box_to_hide.style.display = 'none';

}

}, 20);

}



function box_on(box_id){

var scroll = document.body.scrollTop + document.documentElement.scrollTop;

open_box = box_id;
var box = document.getElementById(box_id);
var dark = document.getElementById('dark_box');
var main = document.getElementById('main_box');
    box.style.opacity = 0; 
    box.style.filter='alpha(opacity=0)'; 

    box.style.left = (getClientWidth()-900)/2 - 100 + 'px';
    box.style.top = (getClientHeight()-729)/2 - 100 + scroll+'px';



box.style.display = 'block';
dark.style.display = 'block';


var from = 0; // Начальная координата X
var to = 1; // Конечная координата X
var duration = 500; // Длительность - 1 секунда
var start = new Date().getTime(); // Время старта
 
setTimeout(function() {
    var now = (new Date().getTime()) - start; // Текущее время
    var progress = now / duration; // Прогресс анимации

    var op = (to - from) * progress + from;

if (op < 0) op=0;
if (op > 1) op=1;
 
    dark.style.opacity = op*0.8; 
    dark.style.filter='alpha(opacity='+op*80+')'; 


    box.style.opacity = op; 
    box.style.filter='alpha(opacity='+op*100+')'; 
 
    if (progress < 1) { // Если анимация не закончилась, продолжаем
        setTimeout(arguments.callee, 10);
}
else{
    box.style.filter='none'; 
}

}, 20);


}

function box_off(box_id){

var box = document.getElementById(box_id);
var dark = document.getElementById('dark_box');

var from = 1; // Начальная координата X
var to = 0; // Конечная координата X
var duration = 500; // Длительность - 1 секунда
var start = new Date().getTime(); // Время старта
 
setTimeout(function() {
    var now = (new Date().getTime()) - start; // Текущее время
    var progress = now / duration; // Прогресс анимации
 
    var op = (to - from) * progress + from;

if (op < 0) op=0;
if (op > 1) op=1;
 
    dark.style.opacity = op*0.8; 
    dark.style.filter='alpha(opacity='+op*80+')'; 

    //box.style.width = op*800+'px';
    //box.style.height = op*600+'px';

    box.style.opacity = op; 
    box.style.filter='alpha(opacity='+op*100+')'; 
 
    if (progress < 1) { // Если анимация не закончилась, продолжаем
        setTimeout(arguments.callee, 10);
}
else{
    box.style.filter='none';  
box.style.display = 'none';
dark.style.display = 'none';

}


}, 10);


}

function getClientWidth() { return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth; }
function getClientHeight() { return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:document.body.clientHeight; }


























function go_pictures(k) {


kod = k;


		anim_w = 680;
		anim_h = 200; 
		blik_dur = 300;
		folder = 'http://evitastudio.ru/img/' + kod + '/';
		speed = 2;
		space = 40;
		stop = 2000;
move = 1;

	x_max = anim_w;
	x_min = 0;

	objPole = document.getElementById("pole");
	objSklad = document.getElementById("sklad");
	objBig = document.getElementById("big_img");

	objPole.style.width = anim_w + 100;
	objPole.style.height = anim_h;


	images = 1;

	x = new Array();


	hand=false;

	id_image = new Array();
	image = new Array();

	mask = new Array();

	x_image = new Array();
	w_image = new Array();
	h_image = new Array();
	timer = new Array();
	pic = new Array(); 
	
	w_pic = new Array();
	h_pic = new Array();


kolvo = 0;

do {
kolvo++;

pic[kolvo] = document.createElement("img");
path = folder + kolvo + '.jpg';
id_pic = 'img_' + kolvo;

pic[kolvo].src = path;
pic[kolvo].id = id_pic;

objSklad.appendChild(pic[kolvo]);

w_pic[kolvo] = getImageSize(id_pic).width;
h_pic[kolvo] = getImageSize(id_pic).height;

} while (pic[kolvo].complete && w_pic[kolvo] >=35);

kolvo = kolvo - 1;



// итог: kolvo - число файлов-картинок

if (kolvo > 3) {

	if (kod!="diploms") document.getElementById("text").style.clear="both";

	dx = move* 1;
	global_x = 0;

	for (n=1; (global_x<=anim_w); n++) {
		for (num=1; (num<=kolvo); num++) {

			x_image[kolvo*(n-1) + num] = global_x;

			global_x = global_x + w_pic[num] + space;
			w_image[kolvo*(n-1) + num] = w_pic[num];
			h_image[kolvo*(n-1) + num] = h_pic[num];

			new_image(x_image[kolvo*(n-1) + num]);
		}
	}

	if  (navigator.appName == 'Netscape' || navigator.appName ==  'Opera') Lightbox.prototype.initialize();

}
if (kolvo != 0 && kolvo <= 3) {


move = 0;
	dx = move* 1;
	global_x = 0;


	n=1; 
		for (num=1; (num<=kolvo); num++) {

			x_image[kolvo*(n-1) + num] = global_x;

			global_x = global_x + w_pic[num] + space;
			w_image[kolvo*(n-1) + num] = w_pic[num];
			h_image[kolvo*(n-1) + num] = h_pic[num];

			new_image(x_image[kolvo*(n-1) + num]);
		}
	


	if  (navigator.appName == 'Netscape' || navigator.appName ==  'Opera') Lightbox.prototype.initialize();
objPole.style.left = "-139px";

}


}





function getImageSize(id) {
    var oHlpr = document.createElement('IMG');
    var oPic = document.getElementById(id);
    oHlpr.style.visibility = 'hidden';
    oHlpr.style.position = 'absolute';
    oHlpr.top = 0; oHlpr.left = 0;
	oHlpr.src = oPic.src;
    document.body.appendChild(oHlpr);


    var imSize = {'width':oHlpr.offsetWidth,'height':oHlpr.offsetHeight };
   

 document.body.removeChild(oHlpr);

 return imSize;

}



function new_image(xx) {

x[images] = xx;
id_image[images] = images;


var xxx = document.createElement("a");
xxx.setAttribute('id', id_image[images]);

if (kod=='diploms') {
xxx.setAttribute('href', 'javascript:scroll(document.body.scrollTop, 640, 500);');
} else {
xxx.setAttribute('href', folder + num + '_big.jpg');
xxx.setAttribute('rel', 'lightbox[roadtrip]');
}

objPole.appendChild(xxx);


var yyy = document.createElement("div");
yyy.setAttribute('id', id_image[images] + '_mask');

objPole.appendChild(yyy);


image[images] = document.getElementById(id_image[images]);
mask[images] = document.getElementById(id_image[images] + '_mask');

image[images].style.cssText = 'z-index: 1; position: absolute; display: none; background: url(' + folder + num + '.jpg) center no-repeat;';
image[images].style.width = w_image[images] + 'px';
image[images].style.height = h_image[images] + 'px';
image[images].style.cursor = 'pointer';
//image[images].style.top = (anim_h - h_image[images]) / 2 + 'px';
image[images].style.bottom = 0 + 'px';

if (kod=='diploms' && (id_image[images] == '3' || id_image[images] == '4' || id_image[images] == '19' || id_image[images] == '14')) {

bg = 'url(' + folder + num + '_mask.jpg) center no-repeat'; 


} else {

bg = '#ffffff';

}

mask[images].style.cssText = 'z-index: 2; position: absolute; display: none; background: ' + bg;
mask[images].style.width = w_image[images] + 'px';
mask[images].style.height = h_image[images] + 'px';
//mask[images].style.top = (anim_h - h_image[images]) / 2 + 'px';
mask[images].style.bottom = 0 + 'px';

mask[images].style.opacity = 0; 
mask[images].style.filter='alpha(opacity=0)'; 

objPole.onmouseover = div_on;
objPole.onmouseout = div_off;

image[images].onclick = div_click;
image[images].onfocus = div_focus;



go(images);

images++;

}



function div_on(e) { 

hand = true;
if (navigator.appName == 'Microsoft Internet Explorer') {
 
xpos = event.x + 200;
 
} else {
 
xpos = e.pageX - (getClientWidth()-1000)/2 - 50;
 
}

dx = move* speed * (anim_w-100 - xpos) / 200;
}


function div_off(e) {
hand = false;
dx = move* 1;

}


function div_focus(e) {
dx = move* 0;
}



function div_click(e) { 

dx = move*  0;
objPole.onmouseover = null;
objPole.onmouseout = null;
pic_to_show = this.id; 
	if (objBig.style.backgroundImage != pic_to_show) {
		fade(1, 0, 500, 'big_img');

		setTimeout(function() {
			fade(0, 1, 500, 'big_img');
			objBig.style.backgroundImage = 'url(' + folder + pic_to_show + '_big.jpg)'; 
		}, 500);



		mask[pic_to_show].style.display = 'block';

		fade(0, 1, blik_dur, id_image[pic_to_show] + '_mask');

		setTimeout(function() { 
			fade(1, 0, blik_dur, id_image[pic_to_show] + '_mask'); 
		}, blik_dur);

		setTimeout(function() { 
			mask[pic_to_show].style.display = 'none';
		}, blik_dur*2);



	}





setTimeout(function() { 

hand = false;
dx = move* 1;
objPole.onmouseover = div_on;
objPole.onmouseout = div_off;

}, stop);

}



function go(number) {

timer[number] = setInterval(function() {



	x[number] = x[number] + dx;

if (x[number] > global_x) x[number] = x[number] - global_x;
if (x[number] <= 0) x[number] = x[number] + global_x;

    image[number].style.left = x[number] + "px";
    mask [number].style.left = x[number] + "px";
	
if (x[number] <= anim_w && x[number] >= 0) {
	image[number].style.display = 'block'; 
} else {
	image[number].style.display = 'none'; 
}
		
if (x[number] <= 100 && x[number] >= 0) {
	image[number].style.opacity = x[number]/100; 
	image[number].style.filter='alpha(opacity=' + x[number]/1 + ')'; 
}	
		
if (x[number] >= anim_w-100  && x[number] <= anim_w ) {
	image[number].style.opacity = (anim_w - x[number] )/100; 
	image[number].style.filter='alpha(opacity=' + (anim_w - x[number])/1 + ')'; 
}

		
	if (x[number] <= anim_w/2 - 30 && x[number] + dx >= anim_w/2 - 30 && hand == false && kod == 'diploms') {

		mask[number].style.display = 'block';

		fade(0, 1, blik_dur, id_image[number] + '_mask');

		setTimeout(function() { 
			fade(1, 0, blik_dur, id_image[number] + '_mask'); 
		}, blik_dur);

		setTimeout(function() { 
			mask[number].style.display = 'none';
		}, blik_dur*2);



		fade(1, 0, 500, 'big_img');

		setTimeout(function() {
			fade(0, 1, 500, 'big_img');
			objBig.style.backgroundImage = 'url(' + folder + number + '_big.jpg)'; 
		}, 500);

	}
	

}, 20);

}


function fade(from, to, duration, id_o) {

var start = new Date().getTime(); // Время старта 

	setTimeout(function fade_out() {
		var now = (new Date().getTime()) - start; // Текущее время
    	var progress = now / duration; // Прогресс анимации

    	var result = (to - from) * progress + from; 
    	document.getElementById(id_o).style.opacity = result; 
    	document.getElementById(id_o).style.filter='alpha(opacity='+result*100+')';  
  
    if (progress < 1) // Если анимация не закончилась, продолжаем
        setTimeout(arguments.callee, 10);
}, 50);

}




function scroll(from, to, duration) {

var start = new Date().getTime(); // Время старта 

	setTimeout(function fade_out() {
		var now = (new Date().getTime()) - start; // Текущее время
    	var progress = now / duration; // Прогресс анимации

    	var result = (to - from)*(2*progress-progress*progress) + from; 

    	window.scrollTo(0,result);  
  
    if (progress < 1) // Если анимация не закончилась, продолжаем
        setTimeout(arguments.callee, 10);
}, 50);

}



