var isMSIE = /*@cc_on!@*/false;

var img_src;
var img_name;
var img_loader;

function set_border(obj)
{
	obj.style.borderColor='#F00';
}

function unset_border(obj)
{
	obj.style.borderColor='#999';
}

function unset_border_(obj)
{
	obj.style.borderColor='#FFF';
}

function set_color(obj)
{
	obj.src = obj.src.replaceEnd('g.jpg','.jpg');
}

function unset_color(obj)
{
	obj.src = obj.src.replaceEnd('.jpg','g.jpg');
}

function show_img(obj)
{
	imgs = obj.parentNode.getElementsByTagName('img');
	len = imgs.length;

	img_src = new Array();
	img_name = new Array();

	for(i=0; i<len; i++)
	{
		if(imgs.item(i) == obj) n=i;
		
		img_name[i] = imgs.item(i).title;
		img_src[i] =  imgs.item(i).src.replaceEnd('.jpg','_.jpg');
	}

	load_img(n);

    window.onresize = function() { move_img(); };
	document.getElementById('hide_box').style.display='';
    document.getElementById('img_box').style.display='';
	move_img();
}

function load_img(n)
{
    img_list_ = document.getElementById('img_list');
	img_list_.innerHTML = '';

    img_ = document.getElementById('img');
	img_.src = 'img/loading.gif';
	img_.style.width = '125px';
	img_.style.height = '125px';
	img_.onclick = function () { if(n==img_src.length-1) load_img(0);
		                         else load_img(n+1); }

    img_loader = new Image();// preload image
	img_loader.onload = function()
	{		
        img_loader.onload = null; 
		img_box_ = document.getElementById('img_box');
		img_box_.style.width = img_loader.width+50+'px';

		img_.style.width = img_loader.width;
		img_.style.height = (img_loader.height>600) ? '600px' : img_loader.height;
		img_.src = img_src[n];
		
		move_img();
	};
	img_loader.src = img_src[n];
	
	document.getElementById('img_name').innerHTML = img_name[n];

    if(n>0) img_list_.innerHTML += '<a href="#" onClick="load_img('+(n-1)+')">назад &lt;</a> ';
	else img_list_.innerHTML += 'назад  < ';

    for(i=0;i<img_src.length;i++)
	{
		if(i!=n) img_list_.innerHTML += '<a href="#" onClick="load_img('+i+')">'+(i+1)+'</a> ';
		else img_list_.innerHTML += '<strong>'+(i+1)+'</strong> ';
	}
	
    if(n<img_src.length-1) img_list_.innerHTML += '<a href="#" onClick="load_img('+(n+1)+')">&gt; далее</a>';
	else img_list_.innerHTML += '> далее';
	
}

function hide_img()
{
	document.getElementById('hide_box').style.display='none';
    document.getElementById('img_box').style.display='none';
}

function move_img()
{
	hide_box_ = document.getElementById('hide_box');

	if(isMSIE)
	{
		hide_box_.style.height =  parseInt(window.document.body.offsetHeight)+ parseInt(document.body.scrollTop); 
		hide_box_.style.width =  parseInt(window.document.body.offsetWidth)+ parseInt(document.body.scrollLeft);
	}
	else
	{
		hide_box_.style.height =  window.document.body.offsetHeight; 
		hide_box_.style.width = window.document.body.offsetWidth;
	}

    img_box_ = document.getElementById('img_box');
	h = (!isMSIE) ? window.innerHeight/2 : parseInt(document.body.clientHeight)/2+parseInt(document.body.scrollTop);
	w = (!isMSIE) ? window.innerWidth/2 : parseInt(document.body.clientWidth)/2+parseInt(document.body.scrollLeft);

   img_box_.style.top = h - parseInt(img_box_.offsetHeight)/2+'px'; 
   img_box_.style.left = w - parseInt(img_box_.offsetWidth)/2+'px';
}
