function makeToggle(id){
	
	if(document.getElementById && document.getElementById(id)){
		
		var obj = document.getElementById(id);
		for(var i=0;i<obj.childNodes.length;i++){
			var node = obj.childNodes[i];
			
			if(node.className && node.className.match(/toggle_control/)){
				node.onclick=function(){
					toggleElement(id);	
				}
			}
		}
		
	}
	
	
}


function toggleElement(id){
	if(document.getElementById && document.getElementById(id)){
		var obj = document.getElementById(id);
		if(obj.className.match(/inactive/)){
			obj.className = obj.className.replace(/inactive/,'active');
		}else{
			obj.className = obj.className.replace(/active/,'inactive');
		}
		
	}
}

var browserPop = null
function photoBrowserPop(url,id){
	var height = 750;
	var width = 750;
	browserPop = window.open(url,'popSized' + height + width,'height='+height+',width='+width+',resizable=yes,scrollbars=yes,toolbar=no,location=no');
	browserPop.insertId = id;
	browserPop.focus();
	
}


var popSized = null;
function popup_sized(url,height,width)
{
	//if (popSized && !popSized.closed)
	//	popSized.location.href = url;
	//else

		
	popSized = window.open(url,'popSized' + height + width,'height='+height+',width='+width+',resizable=yes,toolbar=no,location=no');
	popSized.focus();
	return false;
}

function updateInsertContainer(obj,html,insert_id){
	//var a = document.createElement('a');
	//a.href='<?php echo $html->url("/photos/browser"); ?>';
	//a.onclick = function(){
	//	photoBrowserPop(this.href,obj.id,800,500);return false;
	//	return false;
	//}
	//a.innerHTML = html;
	
	//alert(obj + ' // ' + insert_id);
	
	var w = document.createElement(html.tagName);
	w.className = html.className;
	w.id = html.id
	w.innerHTML = html.innerHTML
	obj.insertBefore(w,obj.firstChild);

}

function resetInsertContainer(obj){
	obj.parentNode.removeChild(obj);
}

function _moveUp(obj){
	
	var sib = obj.previousSibling;
	
	if(sib && sib != 'undefined'){
		var tries = 0;
		while(!sib.tagName && tries < 3){
			if(sib.previousSibling){
				sib = sib.previousSibling;
			}
			tries ++;
		}
		
		
		if(
			sib && 
			sib.tagName == obj.tagName && 
			sib.className  == obj.className
		){
			obj.parentNode.insertBefore(obj,sib);	
		}
	}
	
	//_setListClasses(obj);
	
}

function _moveDown(obj){
	
	var sib = obj.nextSibling;
	/*for(var i in obj){
		if(i.match(/parent|key|index/i)){
		alert(i + ': ' + obj[i]);
		}
	}*/
	
	
	if(sib && sib != 'undefined'){
		var tries = 0;
		while(!sib.tagName && tries < 3){
			if(sib.nextSibling){
				sib = sib.nextSibling;
			}
			tries ++;
		}
		
		
		if(
			sib && 
			sib.tagName == obj.tagName && 
			sib.className  == obj.className
		){
			obj.parentNode.insertBefore(sib,obj);	
		}
	}
	
	//_setListClasses(obj);
	
}

function _setListClasses(obj){
	ct = 0;
	for(var i=0;i<obj.parentNode.childNodes;i++){
		var node = obj.parentNode.childNodes[i];
		
		if(node.tagName){
			if(ct < 1){
				node.className += ' first';
				node.className = node.className.remove(/ last/);
			}else{
				node.className = node.className.remove(/ first/);	
			}
		}
	}
	ct ++;
	node.className += ' last';	
}