var _PG_Thumbs = 5;
var _PG_adjusted = 0;
var _PG_width = 105
var _PG_distance = 10

var _PG_pages = _PG_ImageList.length;
var _PG_container = "slider";

var _PG_SliderStart = _PG_page;
var _PG_SliderEnd = _PG_page + _PG_Thumbs - 1;

function showHide(itemId){
    var element = document.getElementById(itemId);
    if (element != null) {
        if (element.style.display == "none") 
            element.style.display = "block";
        else 
            element.style.display = "none";
    }
}



function showPhoto(imageIndex){
    window.location.href = _PH_BaseUrl + "?c=y&index=" + imageIndex + "&page=" + _PG_page;
    window.event.returnValue = false;
}

function beginSlide(direction, containerId){
    if (((direction == "left") && (_PG_page + _PG_Thumbs >= _PG_pages)) || ((direction == "right") && (_PG_page <= 0))) 
        return;
    
    cameraClicksContainer = document.getElementById(_PG_container);
    if ((direction == 'left') && (_PG_page + _PG_Thumbs > _PG_SliderEnd) && (_PG_SliderEnd < _PG_ImageList.length)) {
        preAdjust(cameraClicksContainer, direction);
        appendImage(_PG_SliderEnd + 1, cameraClicksContainer, 'right');
        _PG_SliderEnd++;
    }
    else 
        if ((direction == 'right') && (_PG_page <= _PG_SliderStart) && (_PG_SliderStart > 0)) {
            preAdjust(cameraClicksContainer, direction);
            appendImage(_PG_SliderStart - 1, cameraClicksContainer, 'left');
            _PG_SliderStart--;
        }

	slidePhoto(direction);
 
}

function preAdjust(container, direction){
    container.width = container.width + _PG_width;
    if (direction == "right") {
        cameraClicksContainer.style.position = "relative";
        position = getPosition(cameraClicksContainer);
        cameraClicksContainer.style.left = (parseInt(position) - _PG_width) + "px";
    }
    
    
    
}

function getPosition(container){
    elementPosition = cameraClicksContainer.style.left;
    elementPosition = elementPosition.replace("px", "");
    elementPosition = elementPosition.replace("pt", "");
    if (elementPosition == "") 
        elementPosition = "0";
    
    return elementPosition;
}

function slidePhoto(direction){

    cameraClicksContainer = document.getElementById(_PG_container);
    
    position = getPosition(cameraClicksContainer);
    
    
    distance = Math.min(_PG_distance, _PG_width - _PG_adjusted);
    if (distance == 0) 
        return;
    
    if (position == "") 
        position = 0;
    if (direction == "left") 
        cameraClicksContainer.style.left = parseInt(position) - distance + "px";
    else 
        cameraClicksContainer.style.left = parseInt(position) + distance + "px";
    
    _PG_adjusted += _PG_distance;
    if (_PG_adjusted < _PG_width) {
    
        window.setTimeout("slidePhoto('" + direction + "')", 20);
    }
    else {
        _PG_adjusted = 0;
        if (direction == "left") {
            _PG_page++;
        }
        
        else {
            _PG_page--;
        }
        
        
        
    }
    
}

function appendImage(index, sliderContainer, side){
    var data = _PG_ImageList[index];
if(data){
    var content = "<div class=\"sliderimg\"><a href=\"javascript:void(0);\" onclick=showPhoto(" + (index + 1) + ");return false;\"><img src=\"" + data + "\" alt=\"\" border=\"0\" /></a></div>";
    if (side == 'right') 
        sliderContainer.innerHTML = sliderContainer.innerHTML + content;
    else 
        sliderContainer.innerHTML = content + sliderContainer.innerHTML;
        
    //alert("appendingindex="+index);
}
}


function buildSlider(){
    cameraClicksContainer = document.getElementById(_PG_container);
    for (i = _PG_SliderStart; i <= _PG_SliderEnd; i++) 
        appendImage(i, cameraClicksContainer, 'right');
    
}

