var Photos = function(contId)
{
    this._images = new Array();
    this._wrapper = document.getElementById(contId);
    this._selected = null;
    this._isIE = (navigator.appName.indexOf("Microsoft") != -1 && parseInt(navigator.appVersion) >= 4);

    this._imgNormal = new Image();
    this._imgNormal.className = 'big';
    this._wrapper.appendChild(this._imgNormal);

    if (this._wrapper == null)
    {
        alert('Container for photos is not found.');
        return;
    }

    this.AddImage = function(normal, thumbnail, title)
    {
        var tmp = new Image();
        tmp.src = normal;
        tmp.alt = title;
        tmp.title = title;

        this._images.push(tmp);

        if (this._images.length == 1)
        {
            this._imgNormal.src = normal;
            this._imgNormal.alt = title;
            this._imgNormal.title = title;
        }

        var tagA = document.createElement('a');
        tagA.href = 'javascript:void(0);';
        tagA.onclick = this.ThumbnailOnClick;
        tagA.owner = this;
        tagA.photoIndex = this._images.length - 1;
        this._wrapper.appendChild(tagA);

        if (this._images.length == 1)
            this._selected = tagA;

        var img = new Image();
        img.src = thumbnail;
        img.alt = title;
        img.title = title;
        this.ChangeOpaicity(img, (this._images.length == 1) ? 100 : 50);
        tagA.appendChild(img);
    }
    this.SetAsSinglePhoto = function()
    {
        if (this._selected != null)
        {
            this._selected.style.display = 'none';
        }
    }
    this.ThumbnailOnClick = function()
    {
        if (this.owner._selected != null)
        {
            this.owner.ChangeOpaicity(this.owner._selected.firstChild, 50);
            this.owner._selected = null;
        }

        this.owner.ChangeOpaicity(this.firstChild, 100);
        this.owner.ChangeImage(this.photoIndex);
        this.owner._selected = this;
    }
    this.ChangeImage = function(index)
    {
        this._imgNormal.src = this._images[index].src;
        this._imgNormal.alt = this._imgNormal.title = this._images[index].alt;
    }
    this.ChangeOpaicity = function(oImg, opacity)
    {
        if (this._isIE)
            oImg.style.filter = "alpha(opacity=" + opacity + ")";
        else
            oImg.style.opacity = opacity / 100;
    }
}