/* Main JavaScript File */

function coDirectorImageChange(moving_index)
{
    var currentSetCount = imageLibrary.rows[imageLibrary.currentRow].count;
    var currentImageIndex = imageLibrary.rows[imageLibrary.currentRow].currentImage;
    if (moving_index < 0)
    {
        if (currentImageIndex > 0)
            currentImageIndex--;
        else
            currentImageIndex = currentSetCount - 1;
    }
    else
    {
        if (currentSetCount > (currentImageIndex + 1))
            currentImageIndex++;
        else
            currentImageIndex = 0;
    }
    imageLibrary.rows[imageLibrary.currentRow].currentImage = currentImageIndex;
    $('coDirectorCurrentImage').src = '';
    $('coDirectorCurrentImage').src = imageLibrary.rows[imageLibrary.currentRow].images[currentImageIndex];            
    $('coDirectorPhotoNum').innerHTML = currentImageIndex+1;
    $('coPhotos').innerHTML = currentSetCount;
}

function $(id)
{
    return document.getElementById(id);
}

function on_resize()
{
    client_w = document.body.clientWidth;
    pb_margin = (client_w - 850) / 8;
    if (pb_margin > 4)
    {
        for (i = 1; i < 5; i++)
        	if ($('pb_'+i) != undefined)
            	$('pb_'+i).style.margin = '0 '+pb_margin+'px';
    }
    if (client_w < 998)
    {
        $('content').style.width = '997px';
        $('footer').style.width = '997px';
    }
    else
    {
        $('content').style.width = '';
        $('footer').style.width = '';        
    }
}

imageLibrary = {
    currentRow:0,
    rows: {
        0: {
            count: 3,
            currentImage: 0,
            images: {
                0: '/var/images/foto/silan_photo.jpg',
                1: '/var/images/foto/silan2.jpg',
                2: '/var/images/foto/silan3.jpg'
            }
        },
        1: {
            count: 1,
            currentImage: 0,
            images: {
                0: '/var/images/foto/mazar_photo.gif'
            }
        },
        2: {
            count: 1,
            currentImage: 0,
            images: {
                0: '/var/images/foto/rizun.jpg'
            }
        },
        3: {
            count: 1,
            currentImage: 0,
            images: {
                0: '/var/images/foto/kloch.jpg'
            }
        }
    }
}

function inactivate_colist()
{
	var listObj = $('coList');
	for (k in listObj.childNodes)
		if (listObj.childNodes[k].tagName == 'LI')
		{
			listObj.childNodes[k].className = '';
			for (sk in listObj.childNodes[k].childNodes)
				if (listObj.childNodes[k].childNodes[sk].tagName == 'IMG')
					listObj.childNodes[k].childNodes[sk].src = '/var/images/right_arrow.gif';
		}
}

function changeCoListItem(obj)
{
	inactivate_colist();
	obj.parentNode.className = 'activeInList';
	for (k in obj.parentNode.childNodes)
		if (obj.parentNode.childNodes[k].tagName == 'IMG')
			obj.parentNode.childNodes[k].src = '/var/images/left_arrow.gif';	
	$('pers_link').className='dTabLink active none'; 
	$('act_link').className = 'dTabLink  none'; 
	$('actual').style.display = 'none'; 
	$('comitetPerson').style.display='block';
	rxp = /coDir_(\d)/;
	block_num = obj.id.match(rxp)[1];
	imageLibrary.currentRow = block_num-1;
	coDirectorImageChange(1);
	coDirectorImageChange(-1);
	var cnt = 1;
	while ($('coBlock_'+cnt)!=null)
	{
		$('coBlock_'+cnt).style.display = 'none';
		cnt++;
	}
	$('coBlock_'+block_num).style.display = 'block';
	$('coName').innerHTML = obj.innerHTML;

}

function selectfirstCoDir()
{
	if ("dTabLink active none" == $('pers_link').className)
	{
		var stoped = false; 
		for (k in $('coList').childNodes) 
			if ($('coList').childNodes[k].tagName == 'LI') 
			{
			
			
				for (sk in $('coList').childNodes[k].childNodes)
					if ($('coList').childNodes[k].childNodes[sk].tagName == 'A')
					{
						$('coList').childNodes[k].childNodes[sk].onclick();
						break;
					}
				break;
			}
	}
}


function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

var big_image = null;
var big_img = null;

function load_image(event)
{
	if (big_image == null)
	{
		big_image = document.createElement('DIV');
		big_image.id = '__big_image';
		big_image.style.border = '1px solid #eee';
		big_image.style.overflow = 'hidden';
		big_image.style.display = 'none';
		big_image.style.position = 'absolute';
		big_image.style.left = '40px';
		document.body.appendChild(big_image);
	}
	if (big_img == null)
	{
		big_img = document.createElement('IMG');
		big_img.id = '__big_img';
		big_img.style.margin = '10px';
		$('__big_image').appendChild(big_img);
	}
}

function display_big_image(event)
{
}

var photosphare = {};
photosphare.big_images = {};