/* JavaScript file */
function photoOpen (url){
	window.open(url, 'new', 'width=520,height=500,toolbar=no,titlebar=no,menubar=no,scrollbars=yes,status=no');
}

function setGalleryImage(id){
    if (photos[id]['image']) {
		//document.getElementById('photoconteiner').innerHTML = photos[id]['image'];
		$("#photoconteiner").html(photos[id]['image']);
        //document.getElementById('photoimage').src  = photos[id]['src'];
	    document.getElementById('photodate').innerHTML = photos[id]['date'];
	    document.getElementById('phototitle').innerHTML = photos[id]['title'];
	    //alert (photos[id]['short']);
		document.getElementById('photoshort').innerHTML = photos[id]['short'];

        

	    return false;
	}
}

var flag;
var timer;
var direction;

function scrollGal(direct, obj){
    flag = true;
    direction = direct;
    timer = window.setInterval('interval()', 1);
    obj.src = obj.src.replace('.gif', '-active.gif');
}

function interval(){
    
    if (flag)
        if (direction == 'left')
            document.getElementById('photo-list').scrollLeft-=3;
        else
            document.getElementById('photo-list').scrollLeft+=3;
    else
        window.clearInterval(timer);
}

function clearTimer(obj){
    obj.src = obj.src.replace('-active.gif', '.gif');
    flag = false;
}



var lastPhoto;


function selectPhoto(obj){
    if (lastPhoto)
        lastPhoto.className = '';
    obj.className='active';
    var item = obj.parentNode.parentNode.parentNode;
    var widthItm = 90; //������ ������
    //var widthMax = document.getElementById('single-photo').offsetWidth; //������ ������������
    var offsetLeft = item.offsetLeft; //������ �����
    var photoList = document.getElementById('photo-list');
    var widthMin = photoList.offsetWidth;//������ �����������
    var scroll = photoList.scrollLeft; //������
    //alert(widthInner);
    
    if (offsetLeft <= scroll + widthItm + 10){
        photoList.scrollLeft = offsetLeft - widthItm;
    }else if (offsetLeft > scroll + widthMin - widthItm - 10){
        photoList.scrollLeft = offsetLeft - widthMin + 2 * widthItm;
    }

    if (item.className.indexOf('last')>=0){
        document.getElementById('right-nav-button').style.visibility = 'hidden';
    }else if (item.className.indexOf('first')>=0){
        document.getElementById('left-nav-button').style.visibility = 'hidden';
    }else{
        document.getElementById('right-nav-button').style.visibility = 'visible';
        document.getElementById('left-nav-button').style.visibility = 'visible';
    }

    lastPhoto = obj;
}


function setPhoto(nav){


    if(lastPhoto){
        var parent = lastPhoto.parentNode.parentNode.parentNode;
        
        if (nav=='prev'){
            parent.previousSibling.getElementsByTagName('img')[0].onclick();
            parent.previousSibling.getElementsByTagName('img')[0].parentNode.onclick();
        }else{
            parent.nextSibling.getElementsByTagName('img')[0].onclick();
            parent.nextSibling.getElementsByTagName('img')[0].parentNode.onclick();
        }
        return false;
    }
}
