var pop_up;
var pop_up_cont;
var gal_array = new Array();
var gal_image = false;

$(document).ready(
	function() {
		$('.persons').bind('click', function() {
				var id;
				var pop_up_all = $('#pop_up_all');
				var top;
				var block_height;
				
				id = $(this).attr('id').replace(/person_/,'');
				$('#pop_up_cont_all').html($('#pd_'+id).html());
				checkWideScreen();
				
				block_height = 271;
				if(myHeight>block_height)
					top = (myHeight/2+myTop-(block_height/1.35)) + "px";
				else
					top = myTop+'px';
				
				pop_up_all.css('top', top);
				pop_up_all.fadeIn(500);
				
				return false;
			}
		);
	}
);

function Person_close() {
	$('#pop_up_all').fadeOut(500);
	return false;
}

function gal_init() {
	pop_up = $('#pop_up');
	pop_up_cont = document.getElementById('pop_up_cont');
	for(i=1; i<=6; i++) gal_array[i] = document.getElementById('gal_cont_' + i);
	// $('.gallery-block').mouseover(function(){}); //for opera fix bug
	// $('.gallery-block .preview div').mouseover(function(){$(this).next().fadeIn(300);}); 
}

function gal_over(cur_obj,ban_id) {
	$(cur_obj).prev().fadeIn(300);
}

function gal_out(cur_obj) {
	if(!gal_image) $(cur_obj).prev().fadeOut(300);
}

function gal_click(num,cur_obj,ban_id) {
	
	pop_up_cont.innerHTML = gal_array[num].innerHTML;
	checkWideScreen();
	pop_up.height(myHeight);
	pop_up.fadeIn(1000);
	gal_image = $(cur_obj).prev();
	
	script = document.createElement("script");
	script.type = "text/javascript";
	script.src = "/ad.js.php?id="+ban_id;		
	document.body.appendChild(script);	
}

function pop_up_close() {
	pop_up.fadeOut(200);
	gal_image.fadeOut(200);
	gal_image = false;
}

function tipo_gal_click(cur_obj_id) {
	var backgr = document.getElementById('layer_back');
	backgr.style.height = $("div.all").height()+'px';
	
	pop_up_cont.innerHTML = $("#" + cur_obj_id).html();
	checkWideScreen();
	pop_up.height(myHeight);
	//	pop_up.fadeIn(1000);
	backgr.style.display = 'block';
	pop_up.css("display","");
}

function tipo_pop_up_close() {
	pop_up.fadeOut(200);
	document.getElementById('layer_back').style.display = 'none';
}

function mapshow(ban_id, lang) {
	
	$('#pop_up_cont').html($('#gal_cont_'+ban_id).html());
	
	if(ban_id)
		$('#map_href').html('<a href="#" onclick="mapshow(0,\''+site_lang+'\'); return false;">'+(site_lang=='en'?'map':'карта')+'</a>');
	else
		$('#map_href').empty();
		
	checkWideScreen();
	$('#pop_up').height(myHeight);
	$('#pop_up').fadeIn(1000);
}

function object_close() {	
	$('#pop_up').fadeOut(200);
}

function checkWideScreen(){
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
    myTop = window.pageYOffset;
    myLeft = window.pageXOffset;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
    myTop = document.documentElement.scrollTop;
    myLeft = document.documentElement.scrollLeft;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
    myTop = document.body.scrollTop;
    myLeft = document.body.scrollLeft;
  }
}

