// $Revision: 11900 $

function doc_all(k){
		if( document.all ) return document.all[k];
		else return document.getElementById(k);
}

function opener_all(k){
	if( document.all ) return opener.document.all[k];
	else return opener.document.getElementById(k);
}

	if (js_show_banners) {
	    var rndnum = Math.round(Math.random() * 999111);
   		if (__show_ad_info_top) {
        	var userid = 117421775; var page = 1;
        	banner_up =
        	   '<div class="banner_up">'+
        		'<iframe src="http://ad4.bannerbank.ru/bb.cgi?cmd=ad&hreftarget=_blank&pubid=' + userid +
        		'&pg=' + page + '&vbn=751&w=-1&h=-1&num=1&r=ssi&ssi=nofillers&r=ssi&nocache=' + rndnum +
        		'&ref=' + escape(document.referrer) + '&loc=" frameborder=0 vspace=0 hspace=0 ' +
        		'width=468 height=60 marginwidth=0 marginheight=0 scrolling=no>' +
        		'<a href="http://ad4.bannerbank.ru/bb.cgi?cmd=go&pubid=' + userid + '&pg=' + page +
        		'&vbn=751&num=1&w=-1&h=-1&nocache=' + rndnum + '&loc=&ref=' + escape(document.referrer) +
        		'" target="_blank"><img src="http://ad4.bannerbank.ru/bb.cgi?cmd=ad&pubid=' + userid +
        		'&pg=' + page + '&vbn=751&num=1&w=-1&h=-1&nocache=' + rndnum + '&ref=' + escape(document.referrer) +
        		'&loc=" width=468 height=60 Alt="Super Exchanger" border=0></a></iframe>'+
        		'</div>';
        }
        else {
        	banner_up =
        	   '<div class="banner_up">'+
        		'<sc'+'ript language="JavaScript" ' +
        		'src="http://adeh.bannerbank.ru/bb.cgi?cmd=ad&hreftarget=_blank&' +
        		'pubid=114819657&pg=1&r=js&ssi=nofillers&vbn=1590&num=1&w=0&h=0&' +
        		'ref=' + escape(document.referrer) + '&loc=&nocache=' +
        		rndnum + '"></sc'+'ript>'+
        		'</div>';
       	}
        banner_down =
        	   '<div class="banner_down">'+
                '<sc'+'ript language="JavaScript" ' +
                'src="http://adeh.bannerbank.ru/bb.cgi?cmd=ad&hreftarget=_blank&' +
                'pubid=114831674&pg=1&r=js&ssi=nofillers&vbn=1590&num=1&w=0&h=0&' +
                'ref=' + escape(document.referrer) + '&loc=&nocache=' +
                rndnum + '"></sc'+'ript>'+
        		'</div>';
	}
	else {
		banner_up   = '';
        banner_down = '';
	}

	if(typeof BASE_DAMOCHKA == 'undefined') BASE_DAMOCHKA = '/';

    if (js_show_long_inf) {
        full_inf_body =
    			'<div style="margin-top:9; margin-bottom:5"><b>ссылка:</b>' +
    			'&nbsp;&nbsp;&nbsp;'+BASE_DAMOCHKA+'sms/info.phtml?key=' +
    			id + '</div>' +
    			'<div style="margin-bottom:12">' +
    			'<a onClick=\'setTimeout("window.close()",1000)\' target=_blank ' +
    			'href="'+BASE_DAMOCHKA+'userinfo.phtml?uid='+id+'">подробная информация (ID ' +
    			id + ') &raquo;</a></div>';
    }

    full_inf_href_up   = banner_up;
    full_inf_href_down = banner_down;

function show_thumbnail(element,num) {
	if( user_photos[num] ){
		imgsrc = user_photos[num][2];
	}
	else  return false;
	var addtop = -105;
	var addleft = -20;
	var rtop=0;
	var rleft=0;
	var thumbdiv=doc_all('thumbdiv');
	var thumbimg=doc_all('thumbimg'+num);
	if (thumbimg.src != imgsrc) thumbimg.src = imgsrc;
	thumbimg.style.display='block';
	do {
		rtop  += element.offsetTop;
		rleft += element.offsetLeft;
		element = element.offsetParent;
	} while (element);

	if (rleft > 400) rleft -=30;
	thumbdiv.style.top=(rtop+addtop)+'px';
	thumbdiv.style.left=(rleft+addleft)+'px';
	thumbdiv.style.display='block';
}

function hide_thumbnail() {
    for (j=0; j<photos_num; j++) {
    	var thumbimg=doc_all('thumbimg'+j);
    	if(thumbimg) thumbimg.style.display='none';
    }
	var thumbdiv=doc_all('thumbdiv');
	if(thumbdiv) thumbdiv.style.display='none';
}

function show_video(k, video_num){
	var video_div;
	var video_ref;
	var video_cur;
	var video_zakl;
	for (i=0; i<video_num; i++){
		video_div = document.getElementById('video_div_'+i);
		video_ref = document.getElementById('video_ref_'+i);
		if ( i == k ){
			video_div.style.display = 'block';
		}
		else{
			video_div.style.display = 'none';
		}
	}
	ostDuring = Math.ceil((k+1) / 10);
	ostFull = Math.ceil(video_num / 10);
	if (ostFull == ostDuring)
		ostd = video_num % 10;
	else
		ostd = 10;
	if (k < 10)
		ekzempl = k;
	else
		ekzempl=k%10;
	if (video_num != 1){
		for(i=0; i<ostd; i++){
			video_div = document.getElementById('video_div_'+i);
			video_ref = document.getElementById('video_ref_'+i);
			video_zakl = document.getElementById('video_zakl_'+i);
			video_cur  = document.getElementById('video_zakl_cur_'+i);
			if ( i == (ekzempl) ){
				video_ref.style.textDecoration = 'none';
				video_cur.style.display = 'block';
				video_zakl.style.display = 'none';
			}
			else{
				video_ref.style.textDecoration = 'underline';
				video_cur.style.display = 'none';
				video_zakl.style.display = 'block';
			}
		}
	}
}

function pager_v(id, num_of_videos,beg_or_end){
	//cсылки на начало и конец
	var prev = document.getElementById('video_zakl_prev');
	var next = document.getElementById('video_zakl_next');
	var pic_video;
	var pic_video_prev = document.getElementById('pic_video_prev');
	var num_of_pages = 10;
	if (beg_or_end == '1'){
		end = id;
		start = id - num_of_pages+1;
		if (start < 0)
			start = 0;
	}
	if (beg_or_end == '0'){
		start = id;
		end = id + num_of_pages-1;
		if (end > num_of_videos)
			end = num_of_videos-1;
	}
	if (start > 0)
	{
		prev.innerHTML='<a id = "video_ref_prev" style="text-decoration:underline;cursor:pointer;cursor:hand;" href="javascript:pager_v('+(start-1)+','+num_of_videos+',1);">&laquo;</a>';
	}
	else
	{
	  prev.innerHTML='<a id = "video_ref_prev" style="text-decoration:none;color:#BFBDBD;cursor:default;" href="javascript:void(0);">&laquo;</a>';
	}
	if (end < num_of_videos-1 )
	{
		next.innerHTML = '<a id = "video_ref_next" style="text-decoration:underline;cursor:pointer;cursor:hand;" href="javascript:pager_v('+(end+1)+','+num_of_videos+',0);">&raquo;</a>';
		pic_video_prev.innerHTML ='<img src="'+ BASE_STATIC+'main/section_devsm.gif" width="5" height="20" border="0">';
	}
	else
	{
		next.innerHTML = '<a id = "video_ref_next" style="text-decoration:none;color:#BFBDBD;cursor:default;" href="javascript:void(0);">&raquo;</a>';
		pic_video_prev.innerHTML ='';
	}
	var video_num = start+1;
	var video_zak;
	var video_cur;
	for(i=0; i<num_of_pages; i++){
		if(start <= end){
			video_zakl = document.getElementById('video_zakl_'+i);
			video_cur  = document.getElementById('video_zakl_cur_'+i);
			video_zakl.innerHTML ='<a  id = "video_ref_'+i+'"  href="javascript:show_video('+start+','+num_of_videos+');">'+video_num+'</a>';
			video_cur.innerHTML ='<a class="Current">'+video_num+'</a>'
			pic_video  = document.getElementById('pic_video_'+i);
			pic_video.innerHTML = '<img src="'+ BASE_STATIC+'main/section_devsm.gif" width="5" height="20" border="0">';
			start++;
			video_num++;
		}else{
			video_zakl = document.getElementById('video_zakl_'+i);
			//pic_video  = document.getElementById('video_zakl_'+i);
			video_zakl.innerHTML ='<a  id = "video_ref_next" style="text-decoration:none;color:#BFBDBD;cursor:default;" href="javascript:void(0);">&raquo;</a>';
			pic_video_prev.innerHTML = '';
			next.innerHTML='';
			start++;
			new_start = start - ((id/10)*10);
			while (new_start < 10){
				video_zakl = document.getElementById('video_zakl_'+new_start);
				pic_video  = document.getElementById('pic_video_'+new_start);
				video_cur  = document.getElementById('video_zakl_cur_'+new_start);
				video_cur.innerHTML = '';
				pic_video.innerHTML = '';
				video_zakl.innerHTML = '';
				new_start++;
			}
			break;
		}
	}

	show_video(id, num_of_videos);
}

function set_photo(k){
	var bigrace;

	var photo_div;
	var photo_img;
	/*
if (user_photos[k][5])
{
	document.getElementById("div_gul").style.display="block";
	document.getElementById("div_gul_pid").value= user_photos[k][3];
}
else
{
	document.getElementById("div_gul").style.display="none";
}*/
	hide_thumbnail();
	if (user_photos[k]) {
    	imgsrc = user_photos[k][1];
	}

	else  return false;

	for (j = 0; j < photos_num; j++) {
		bigrace        = doc_all("bigrace"         + j);
		if(bigrace       ) bigrace.style.display        = (j == k) ? '' : 'none';

		photo_img      = doc_all("photo_img"       + j);
		if(photo_img     ) photo_img.style.display      = (j == k) ? 'block' : '';

		photo_div      = doc_all("photo_div"       + j);
		if(photo_div     ) photo_div.style.display      = (j == k) ? '' : 'none';

		photo_zakl     = doc_all("photo_zakl_"     + j);
		if(photo_zakl    ) photo_zakl.style.display     = (j != k) ? '' : 'none';

		photo_zakl_cur = doc_all("photo_zakl_cur_" + j);
		if(photo_zakl_cur) photo_zakl_cur.style.display = (j == k) ? '' : 'none';
	}

	photo_img = doc_all("photo_img" + k);
	var Konfetka = document.getElementById('konfetka_waiter');
	if (typeof PHOTOTimeout != 'undefined' && PHOTOTimeout){
		clearTimeout(PHOTOTimeout);
		PHOTOTimeout = null;
	}
	Konfetka.style.display = 'none';
	if (!photo_img.IsComplete){
		photo_img.src = user_photos[k][2];
		Konfetka.style.display = '';
		PHOTOTimeout = setTimeout(function(){
			var IMG__ = new IMGPreloader();
			IMG__.AddItem(user_photos[k][1]);
			IMG__.OnComplete = function(){
					var F = function(){
						Konfetka.style.display = 'none';
						if (photo_img.IsComplete) return false;
				    	photo_img.IsComplete = true;
					}
					photo_img.onload = F;
					photo_img.onerror = function(){
						if (!this.Try) this.Try = 0;
						this.Try++;
						if (this.Try < 5)
							this.src = user_photos[k][1];
						else{
							this.onerror = null;
							F();
						}
					}
					photo_img.src = user_photos[k][1];
					if (ThisBrowser.IsOpera){
						Konfetka.style.display = 'none';
				    	photo_img.IsComplete = true;
					}
			}
			IMG__.Create();
		},500);
	}

}

function pager(id, num_of_photos,beg_or_end){
	var prev = document.getElementById('Prev');
	var next = document.getElementById('Next');
	var end_pic = document.getElementById('end_pic');
	var f_prev  = document.getElementById('f_prev');
	var next_td_pic = document.getElementById('next_td_pic');
	var next_td_data = document.getElementById('next_td_data');

	var num_of_pages = 10;
	var change = num_of_pages - id;
	if (beg_or_end == '1'){
		end = id;
		start = id - num_of_pages+1;
		if (start < 0)
			start = 0;
	}
	if (beg_or_end == '0'){
		start = id;
		end = id + num_of_pages-1;
		if (end >= num_of_photos)
			end = num_of_photos-1;
	}
	if (start > 0){
		f_prev.style.display  = '';
	    prev.style.display  = 'block';
		prev.innerHTML='<a style = "cursor:pointer; cursor:hand;" href="javascript:set_photo('+(start-1)+');" onclick="pager('+(start-1)+','+ num_of_photos+',1);">&laquo;</a>';
	}
	else{
	  prev.innerHTML='<a style="text-decoration:none;color:#BFBDBD; cursor:default;" href="javascript:void(0);" onclick="void(0);">&laquo;</a>';
	}

	if (end < num_of_photos-1){
		next.innerHTML = '<a style = "cursor:pointer; cursor:hand;" href="javascript:set_photo('+(end+1)+');" onclick="pager('+(end+1)+','+ num_of_photos+',0);" >&raquo;</a>';
		end_pic.innerHTML = '<img src="'+ BASE_STATIC+'main/section_devsm.gif" width="5" height="20" border="0">';
		end_pic.style.display = '';
		next.style.display = '';
		next_td_pic.style.display = '';
	    next_td_data.style.display = '';

	}
	else{
		next.innerHTML = '<a style="cursor:default; text-decoration:none;color:#BFBDBD;" href="javascript:void(0);" onclick="void(0);" >&raquo;</a>';
		end_pic.innerHTML = '<img src="'+ BASE_STATIC+'main/section_devsm.gif" width="5" height="20" border="0">';
		end_pic.style.display = '';
		next.style.display = '';
		next_td_pic.style.display = '';
	    next_td_data.style.display = '';
	}
	var Photo_num = start+1;
	var main_div;
	var main_td;
	var pic_td;
	for(i=0; i<num_of_pages; i++){
		var st = 'photo_' + i;
		main_div = document.getElementById('photo_' + i);
		main_td  = document.getElementById('td_' + i);
		pic_td   = document.getElementById('pic_' + i);
		pic_td.style.display = '';
		main_td.style.display = '';
		if (start <= end){
			main_td.setAttribute('title',user_photos[start][0]);
			main_td.setAttribute('alt' , user_photos[start][0]);
			pic_td.innerHTML = '<img src="'+ BASE_STATIC+'main/section_devsm.gif" width="5" height="20" border="0">';
			main_div.innerHTML = '\
                        	  	<div id="photo_zakl_'+start+'" style="display: block;">\
                             		<a style ="padding-right:2px;" href="javascript:set_photo('+start+');" onmouseover="show_thumbnail(this, '+start+');" onmouseout="hide_thumbnail();">'+Photo_num+'</a>\
                        		</div>\
                        		<div id="photo_zakl_cur_'+start+'" style="display: none;">\
                            		<a class="Current">'+Photo_num+'</a>\
                        		</div>';
			start++;
			Photo_num++;
		}
		else{
			main_div.innerHTML = '<a style= "cursor:default; text-decoration:none; color:#BFBDBD;" href="javascript:void(0);" onclick="void(0);" >&raquo;</a>';
			pic_td.innerHTML = '<img src="'+ BASE_STATIC+'main/section_devsm.gif" width="5" height="20" border="0">';
			next.innerHTML = '';
			end_pic.innerHTML = '';
			end_pic.style.display = 'none';
			//main_td.style.display = 'none';
			next.style.display = 'none';
			next_td_pic.style.display = 'none';
	    	next_td_data.style.display = 'none';
			start++;
			if (beg_or_end == '0')
				new_start = start - id;
			else
				new_start = start;
			while (new_start < 10){
				main_div = document.getElementById('photo_' + new_start);
				main_td  = document.getElementById('td_' + new_start);
				pic_td   = document.getElementById('pic_' + new_start);
				main_div.innerHTML = '';
				pic_td.innerHTML = '';
				pic_td.style.display = 'none';
				main_td.style.display = 'none';
				new_start++;
			}
			break;
		}

	}
	set_photo(id);
}
