/* test commit*/
OnLoadPortfolio = function (ids)  {

	/* methods */
	
 	this.displayNavColNavigation = function () {
 		if (this.cnt_im == 1) return;
 		var nav_col_height = this.img_height[this.old_id];
    	var flag = (this.img_top_pos[this.cnt_im] + this.img_sm_height[this.cnt_im] + this.image_padding_bottom > nav_col_height);
    	var nav_col = this.getById("nav_col_block");
	    if (!flag && this.old_id > this.cnt_im) {
	        this.old_id = this.old_id - this.cnt_im;
	        nav_col_height = this.img_height[this.old_id];
	    }
	    if (this.old_id < this.cnt_im / 2) {
	        this.old_id = this.old_id + this.cnt_im;
	    } else if (this.old_id > 3 * this.cnt_im / 2) {
	        this.old_id = this.old_id - this.cnt_im;
	    }
    	var display_type = (flag) ? 'block' : 'none';

	    if (!flag && !ie) {
	        //alert(this.getById('nav_col_block').style.marginTop);
	        //this.getById('nav_col_block').style.marginTop = '3px';
	    }

	    if (this.cnt_im > 1) {
	        for (var i = this.cnt_im + 1; i <= this.img_height.length; i++) {
	            if (this.getById("href_" + i) != null) {
	                this.getById("href_" + i).style.display = display_type;
	            }
	        }
	        this.getById("nav_col_button_up").style.display = display_type;
	        this.getById("nav_col_button_down").style.display = display_type;
	    }

	    if (flag) {
	        //nav_col_height = Math.floor(nav_col_height) - this.button_height * 2 + 20;
	        var top_pos = this.getNewTopPosition(this.old_id);
	        if (top_pos > 0) {
	            this.old_id = this.cnt_im + this.old_id;
	            top_pos = this.getNewTopPosition(this.old_id);
	        }
	        this.getById("nav_col_block_box").style.top = this.getNewTopPosition(this.old_id) + 10 + 'px';
	    } else {
	        this.getById("nav_col_block_box").style.top = '0px';
	    }
	    if (nav_col_height < this.min_panel_height) {
	        nav_col_height = this.min_panel_height;
	    }
    	nav_col.style.height = nav_col_height > 250 ? nav_col_height + 'px' : '80%';
 	}
 	
 	
 	this.OnSelectImage = function (id) {
 		if (this.old_id == id) {
        	return false;
    	}
/*    if (flag != 1 && id < cnt_im) {
        id = id + cnt_im;
    }
*/
	    for (var i = 1; i <= this.cnt_im * 2; i++) {
	        this.getById("href_"+i).className = "";
	    }
	    this.old_id = id;
	
	    this.displayNavColNavigation();
	    /*var main_img = this.getById("main_img_id");*/
	    
	    main_img = this.getById('main_img_id');
	    main_img.style.visibility = "hidden";
	    main_img.src = this.getById("im_"+this.old_id).value;
	    main_img.height = this.img_height[this.old_id];
	    main_img.width = this.img_width[this.old_id];
	
	    this.getById("href_"+this.old_id).className = "this_proj";
	    if (this.old_id <= this.cnt_im) {
	        this.getById("href_"+(this.old_id + this.cnt_im)).className = "this_proj";
	    } else {
	        this.getById("href_"+(this.old_id - this.cnt_im)).className = "this_proj";
	    }
	    this.getById("href_"+this.old_id).blur();
	
	    var im_sm_href = this.getById("im_sm_" + this.old_id).value;
	    this.getById("fl_scr").style.visibility = (im_sm_href == main_img.src) ? "hidden" : "visible";
	
	    this.getById("fl_scr").href = im_sm_href;
	    var descr = this.getById("desc_" + this.old_id);
	    if (descr != null) {
	        this.getById("descr").innerHTML = descr.value;
	    }
	
	    var height = main_img.height + 30;
	    if (ie) {
	        this.getById('nav_column_id').style.height = height + 'px';
	    }
	    height = height + 40;
	    if (ie) {
	        height = height + 30;
	    }
	    $('popup_viewphoto').style.height = height + 'px';
	
	    return false;
 	}
 	
 	this.OnSelectPrev = function (ids) {
		this.OnSelectImage((this.old_id <= this.cnt_im) ? (this.old_id - 1 + this.cnt_im) : (this.old_id - 1), ids);
    }

    this.OnSelectNext  = function (ids) {
    	this.OnSelectImage((this.old_id > this.cnt_im) ? (this.old_id + 1 - this.cnt_im) : (this.old_id + 1), ids);
	}
	
	this.getById  = function  (id) {
		
		if (this.ids != null && $(id + '_' + this.ids)) {
			return $(id + '_' + this.ids);
		}
		else if  ($(id)) {
			return $(id);
		}
	}
	
	this.getNewTopPosition  = function (ind) {
   		var result = Math.ceil((this.img_height[ind] - 2 * this.button_height + 20) / 2) - this.img_top_pos[ind] - Math.ceil(this.img_sm_height[ind] / 2) - this.button_height;
    	return result;
	}
	
	/* properties */
	 this.ids = (ids) ? ids : null;
 	 this.old_id = 1,
	/* расстояние между рисунками */
	this.image_padding_bottom = 20;
	/* массив координат Y верхней границы рисунков */
 	this.img_top_pos = new Array();
	/* массив высот рисунков */
 	this.img_height = new Array();
	/* массив ширины рисунков */
 	this.img_width = new Array();
	/* массив размеров минимизированных рисунков */
 	this.img_sm_height = new Array();
	/* высота кнопок управления */
 	this.button_height = 20;
	/* количество рисунков */
 	this.cnt_im = 0;
	/* минимальная высота полосы прокрутки */
 	this.min_panel_height = 100;
 	this.current_img = 0;
 	this.cnt_im = parseInt(this.getById('cnt_img').value);
    var sHref = "JavaScript:void(0)";
    var el;
    var i, i2;
    el = this.getById("fl_scr_im");
    if (el != null) {
        el.href = sHref;
    }
    el = this.getById("current_img");
    if (el != null) {
        this.current_img = parseInt(el.value);
    }
    /* учитываем бордеры рисунков для IE */
    var border = (!ie) ? 0 : 2;

    for (i2 = 0; i2 < 2; i2++) {
        for (i = 1; i < this.cnt_im + 1; i++) {
            if (!i2) {
                el = this.getById("href_" + i);
                if (el != null) {
                    el.href = sHref;
                }
            }
            if (this.getById("im_" + (i + i2 * this.cnt_im)) == null) continue;
            this.img_sm_height[i + i2 * this.cnt_im] = parseInt(this.getById("im_sm_height_" + (i + i2 * this.cnt_im)).value) + border;
            this.img_height[i + i2 * this.cnt_im] = parseInt(this.getById("im_height_" + (i + i2 * this.cnt_im)).value);
            this.img_width[i + i2 * this.cnt_im] = parseInt(this.getById("im_width_" + (i + i2 * this.cnt_im)).value);
            if (i > 1 || i2) {
                this.img_top_pos[i + i2 * this.cnt_im] = this.img_top_pos[i + i2 * this.cnt_im - 1] + this.img_sm_height[i] + this.image_padding_bottom;
            } else {
                this.img_top_pos[1] = 0;
            }
        }
    }
    el = this.getById("href_1");
    if (el != null) {
        el.className = "";
    }
    el = this.getById("current_img");
    if (el != null) {
        this.old_id = parseInt(el.value);
    }

    var but = this.getById("close_button");
    if (but != null) {
        but.style.visibility = "visible";
    }
    but = this.getById("logo_button");
    if (but != null) {
        but.href = sHref;
    }
    this.displayNavColNavigation();
    if (this.cnt_im > 1) {
    	this.getById("nav_col_block_box").style.position = "absolute";
   	}

    this.getById("im_prev").style.visibility = (this.cnt_im > 1) ? "visible" : "hidden";
    this.getById("im_next").style.visibility = (this.cnt_im > 1) ? "visible" : "hidden";

    el = this.getById("im_next");
    if (el != null) {
        el.href = sHref;
    }
    el = this.getById("im_prev");
    if (el != null) {
        el.href = sHref;
    }
    this.getById("href_"+this.old_id).className = "this_proj";
    if (this.old_id <= this.cnt_im) {
        this.getById("href_"+(this.old_id + this.cnt_im)).className = "this_proj";
    } else {
        this.getById("href_"+(this.old_id - this.cnt_im)).className = "this_proj";
    }
    this.OnSelectImage(this.old_id, null);
}