
/*
sets onclick handler 
*/
function InitLinkOnClick() {
   
	if ( !document.getElementsByTagName) return;
	
	var links = document.getElementsByTagName('a');
	
	for (i=0; i<links.length; i++)
	{
		if ( links[i].onclick != null ) continue;
		switch(links[i].className) 
		{
			case 'lnk_win':
				links[i].onclick = lnk_win_onclick;
			break;
			case 'lnk_photo':
				links[i].onclick = lnk_photo_onclick;
			case 'lnk_popup':
				links[i].onclick = lnk_popup_onclick;				
			break;		
		}
	}
}


function lnk_win_onclick() 
{
	window.open(this.href, '_blank');
	return false;
}

function lnk_popup_onclick() 
{
	window.open(this.href, '_blank', 'toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1,width=700');
	return false;
}

function lnk_photo_onclick() 
{
	var w = window.open('', '', 'toolbar=0,location=0,status=0,menubar=0,scrollbars=1,resizable=1,width=700');

	if (!w) return true;
	
	var win_title = GetWinTitle(this);

	w.document.open();
	var content = "<html>"+
		"<head>"+
		"<title>"+win_title+"</title>"+
		"</head>"+    	
		"<body>"+
		"<center><img src='"+this.href+"'/></center>" +
		"</body></html>";
	w.document.write(content);
	w.document.close();
	
	return false;
}

/* 
gets title from alt attribute of img tag if it is specified or from title attrib of anchor
*/
function GetWinTitle(anchor) {
	
	var win_title = (anchor.title!=null ? anchor.title : "");
	var p1, p2;
	var s = anchor.innerHTML.toLowerCase();
	if( s.indexOf('<img ', 0) == 0 ) {
		p1 = s.indexOf(' alt="', 0);
		if( p1 == -1 ) return win_title;
		p1 = p1 + 6; 
		p2 = s.indexOf('"', p1);
		if( p2 == -1 ) return win_title;
		win_title = anchor.innerHTML.substring(p1,p2);
	} 
	
	return win_title;	
}
