var win=0;
function popUp (img,w,h,msg,winTitle) {
	if(win) { 
		if(!win.closed) {win.close();} 
		}
	
		 w+=40;	h+=80;
		if (!winTitle) winTitle="Фотография"
	win = window.open('','','menubar=no,directories=no,location=no,resizable=yes,scrollbars=1, toolbar=no, width='+w +',height='+h);
	
	win.document.open()
	win.document.write('<html><head><title>'+winTitle+'</title>')
	win.document.write('<link rel="stylesheet" type="text/css" href="/css/popup.css"/>')
	win.document.write('</head><body>')
	
	win.document.write('<div class="pic"><img src="'+img+'"/></div>')
	win.document.write('<div class="msg">'+msg+'</div>')
	win.document.write('</body></html>')
	win.document.close()
	
	return false;
	}
	

	
function showPhoto (num) {
	var wOffset=50,
		hOffset=80,
		d=photos[num],
		winContent='<div id="content">'+getContent(photos,num)+'</div>',
		WN = window.open('','WN_'+num,'titlebar=yes,scrollbars=1, status=1,width='+(d.w+wOffset) +',height='+(d.h+hOffset)),
		preO=	'<head><title>'+groupTitle+'</title>'+
				'<link rel="stylesheet" type="text/css" href="/css/popup.css" />'+
				'<script>'+placePhoto+'</script>'+
				'</head>'
	if (!WN.document.body) winContent='<body>'+winContent+'</body>'
	preO+=winContent

	WN.document.open()
	WN.document.write(preO)		
	WN.document.close()

	
	return false;
	}
function getContent(pData,num){
	var d=pData[num],
		pFunc='placePhoto',
		beforeCaption="Назад",
		afterCaption="Вперёд",
		nextNum=(num>=pData.length-1)?1:num+1
		before=(num>1)?'<a href="#" onclick="return '+pFunc+'('+(num-1)+')">'+beforeCaption+'</a>':beforeCaption,
		after='<a href="#" onclick="return '+pFunc+'('+nextNum+')">'+afterCaption+'</a>'
		res='<div class="pic"><a href="#" onclick="return '+pFunc+'('+nextNum+')"><img src="'+d.src+'.jpg" alt="" width="'+d.w+'" height="'+d.h+'" /></a></div>'
			+'<div class="msg">'+d.comment+'</div>'
			+'<div class="navy"><span id="before">'+before+'</span><span id="after">'+after+'</span><span class="clear">&nbsp;</span></div>'
	return res
	}
function placePhoto(num){var pData=window.opener.photos,cBlock=window.document.getElementById('content');cBlock.innerHTML=window.opener.getContent(pData,num);return false}	
	
function showPhotos(){
	var cBlock=document.getElementById('photos-content'),
		o='',
		h='<h2>'+groupTitle+'</h2>',
		b='<div class="backlink"><a href="/photo/">Остальные альбомы</a></div>'

	for (var i=1; i<photos.length; i++){
		var data=photos[i]
		o+='<li><a href="#" onClick="return showPhoto('+i+')"><img src="'+data.src+'s.jpg" alt="" width="120" height="80"></a></li>'
		
		}
		o=h+'<ul class="prevs">'+o+'</ul>'+b
		
		cBlock.innerHTML=o
	}
	
	
	
/* Collapses
=================================================*/
	GLOBAL_EVENTS.append("onload","collapse_caman")
	var Collapses={},
		collapseAll,
		collapseDefault=[]
	function collapse_caman(){
		
		var collapseLinks=getElementsByTagAndClass(document.body,"SPAN","collapse-link");
		
		if (!collapseLinks || collapseLinks.length==0) return
		collapseAll=$id("collapse-all")
		
		//rewrite collapseDefault:
		var wl=window.location+"",
			indAnchor=wl.indexOf("#")
		if (indAnchor>0){
			var anch=wl.substr(indAnchor+1),
				aBlock=$id(anch)
				if(aBlock && aBlock.className && aBlock.className.search("collapse")>=0){
					collapseDefault=new Array(anch);
					}
			
			}
		
		for (var i=0;i<collapseLinks.length;i++){
			var cLink=collapseLinks[i],
				cLinkIDArray=cLink.id.split("_"),
				cID=cLinkIDArray[0]
				
			cLink.obj={collapseID:cID}
				
			cLink.className+=" active"
			cLink.onclick=collapse
			Collapses[cID]={c:cID,state:0}
			
			if (collapseDefault && collapseDefault.length>0 && in_array(collapseDefault,cID))
				Collapses[cID].state=switchElementVisibility(cID)
		
			}
			switchCollapseAll()
		
		}
	
	function collapse(e){
		switchCollapseAll(0,this.obj.collapseID)
		Collapses[this.obj.collapseID].state=switchElementVisibility(this.obj.collapseID)
		
		//alert(Collapses[this.obj.collapseID].state)
		}
				
	function switchElementVisibility(el,state){
		var states=new Array('hidden','showed'),
			newState,
			currState=0
		//alert (el+" '"+$id(el).className+"' state="+state)
		el=$id(el)
		
		if (el.className && el.className.search(states[0])>-1)
			currState=0
		else if (el.className && el.className.search(states[1])>-1)
			currState=1
		newState=(state==null)?((currState==0)?1:0):state
	
		var strTempl='/'+states[currState]+'/'
	
		if (el.className && el.className.search(states[currState])>-1)
			el.className=el.className.replace(states[currState], states[newState])
		else 
			el.className+=" "+states[newState]
			
		return newState
		}
		
	function switchCollapseAll(state,except){
		//if (!collapseAll) return
		var showed=0,
			hidden=0,
			summ=0,
			o=''
		for (var i in Collapses){
			var c=Collapses[i]
			if (c.state==1)
				showed++
			else 
				hidden++
			}
		summ=showed+hidden
		
	
		if (state!=null){
			
			newAllState=state?1:0
			if (newAllState){
				hidden=0
				showed=summ
				}
			else {
				showed=0
				hidden=summ
				}
				
			//alert (newAllState)
			for (var i in Collapses){
				if (except && i==except) continue
				var c=Collapses[i]
				Collapses[i].state=switchElementVisibility(c.c,newAllState)
				//alert($id(c.c).className)
				}
			}
		
		/* if (showed) o+='<a onclick="switchCollapseAll(0)">Свернуть всё</a>'
		if (hidden) o+=((o!='')?'&nbsp;|&nbsp;':'')+'<a onclick="switchCollapseAll(1)">Развернуть всё</a>'
		collapseAll.innerHTML=o
 */			
			//alert (Collapses.length)
		}
