
function hkObj(id) 
{
	return document.getElementById(id);
}

function hkParseInt(str)
{
	var number = parseInt(str);
	if (isNaN(number)) number = -1;
	return number;
}

function hkAlertObjProps(obj, showValues) 
{
	var buf = '';
	for (var prop in obj) 
	{
		buf += ' ' + prop;
		if (showValues) buf += '=' + obj[prop] + ' '
	}
	alert(buf);
}


function hkPopupWindow(url,width,height,scroll) {
	var popUpWin = 0;
	
	if (scroll==null) scroll=false;
	
	if(popUpWin) {
		if(!popUpWin.closed) popUpWin.close();
	}

	var left = (screen.width/2) - width/2;
  	var top = (screen.height/2) - height/2;
  	var scrolling = (scroll)?'yes':'no';

	popUpWin = open(url, '', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars='+scrolling+',resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
	popUpWin.focus();
}


function hkToggleBlockDisplay(id) {
	var obj = hkObj(id);
	if (obj && obj.style) {
		if (obj.style.display=='none') obj.style.display = '';
		else obj.style.display = 'none';
	}
}

function hkShowBlock(id) {
	var obj = hkObj(id);
	if (obj) {
		obj.style.display = '';
	}
}

function hkHideBlock(id) {
	var obj = hkObj(id);
	if (obj) {
		obj.style.display = 'none';
	}
}

function showImage(what,w,h,root,title) {
	var scroll=0;
	if (w>screen.width) {
		w=screen.width;
		scroll=1;
	}
	if (h>screen.height) {
		h=screen.height;
		scroll=1;
	}

	var left = (screen.width/2) - w/2;
  	var top = (screen.height/2) - h/2;

	var opt='toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars='+scroll+',height='+h+',width='+w+',top='+top+',left='+left;
	
	var titleAdd = '';
	if (title) {
		titleAdd = '&title='+escape(title);
	}
	
	var wnd= window.open(root+'showimage.php?name='+what+titleAdd,'',opt);
	wnd.focus();
}

function hkBindFancybox(selector)
{
	if (!$().fancybox) return;

	$(selector).fancybox({
		'titleShow': true,
		'titlePosition'	: 'inside',
		'overlayOpacity' : 0.7,
		'overlayColor' : '#000',
		'cyclic' : true,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'titleFormat' : function(title, currentArray, currentIndex, currentOpts) 
		{
			if (!title) title = '';
			if (currentArray.length > 1)
			{
				return 'Изображение ' + (currentIndex + 1) + ' из ' + currentArray.length + (title.length ? ': &nbsp; ' + title : '');
			}
			else return title;
		}
	});
}

$(document).ready(function(){
	
	hkBindFancybox('.hkZoom');


  $("input, textarea").focus(function(){
    if ($(this).attr("value") == $(this).attr("title"))
      $(this).attr("value", "")
  });

  $("input, textarea").blur(function(){
    if ($(this).attr("value") == "")
      $(this).attr("value", $(this).attr("title"))
  });


});


