function $(id){
	var o = document.getElementById(id);
	return(o);
}
function edit(name, type){
	$('divDimmer').style.display = 'block';
	$('divDimmer').style.visibility = 'visible';
	$('editDialog').style.display = 'block';
	$('editDialog').style.visibility = 'visible';
	setPaths(name, type);
	if(type=='text'){
		$('editDescription').innerHTML = pv['text'][name][0]['description'];
		$('editTitle').innerHTML = pv['text'][name][0]['title'];
		//document.frmEdit.path.value = pv['text'][name][0]['path'];
		document.frmEdit.id.value = pv['text'][name][0]['id'];
		document.frmEdit.type.value = 'text';
		$('divText').style.display = 'block';
		$('divImage').style.display = 'none';
		document.frmEdit.text.value = pv['text'][name][0]['value'];
		CKEDITOR.replace('text',{enterMode:CKEDITOR.ENTER_BR});
		
	}else if(type=='images'){
		switchTab($('curImage'));
		$('editDescription').innerHTML = pv['images'][name][0]['description'];
		$('editTitle').innerHTML = pv['images'][name][0]['title'];
		//document.frmEdit.path.value = pv['images'][name][0]['path'];
		document.frmEdit.id.value = pv['images'][name][0]['id'];
		document.frmEdit.type.value = 'images';
		document.frmEdit.imagename.value = pv['images'][name][0]['image'];
		document.frmEdit.alt.value = pv['images'][name][0]['alt'];
		document.frmEdit.width.value = pv['images'][name][0]['width'];
		document.frmEdit.height.value = pv['images'][name][0]['height'];
		$('divImage').style.display = 'block';
		$('divText').style.display = 'none';
		$('uploadImage').className = 'tab';
		$('curImage').className = 'tabSel';
		$('imageEdit').style.display = 'block';
		$('imageThumb').src = imageDir + pv['images'][name][0]['image'];
		$('imageThumb').style.width = '';
		$('imageThumb').style.height = '';
		var w = pv['images'][name][0]['width'];
		var h = pv['images'][name][0]['height'];
		var ws = 575/w;
		var hs = 200/h;
		if(ws < hs){
			$('imageThumb').style.width = '575px';
		}else{
			//alert(pv['images'][name][0]['height']);
			$('imageThumb').style.height = '200px';
		}
		document.frmEdit.map.value = pv['images'][name][0]['map'];
	}
}
function closeEditDialog(){
	$('divDimmer').style.display = '';
	$('divDimmer').style.visibility = '';
	$('editDialog').style.display = '';
	$('editDialog').style.visibility = '';
	$('textPrompt').style.display = '';
	if(typeof(CKEDITOR.instances.text)=='object'){
		CKEDITOR.instances.text.destroy();
	}

}
function expandEditTab(){
	$('editHeaderDiv').style.display = 'block';
}
function contractEditTab(){
	$('editHeaderDiv').style.display = '';
}
function switchTab(t){
	//alert(t.id);
	if(t.id == 'curImage'){
		t.className = 'tabSel';
		$('uploadImage').className = 'tab';
		$('imageEdit').style.display = 'block';
		$('imageUpload').style.display = 'none';
		$('submit').style.display = '';
	}else{
		t.className = 'tabSel';
		$('curImage').className = 'tab';
		$('imageEdit').style.display = 'none';
		$('imageUpload').style.display = 'block';
		$('submit').style.display = 'none';
		$('frmImage').parentDocument = document;
	}
}
function setPaths(name, type){
	var activePath = pv[type][name][0]['path'];
	//alert(curPath);
	var o = $('paths');
	//remove existing options
	while(o.length>0){
		o.remove(0);
	}
	//add various paths

	//add current path
	document.frmEdit.path.value	= curPath;
	if(curPath != activePath){
		//add current path
		var opt = 'this page (' + curPath + ')';
		try{
			o.add(new Option(opt,curPath),true,true,null);
		}catch(e){
			o.add(new Option(opt,curPath),true,true);
		}
	}
	//add active path
	if(activePath!='/'){
		var opt = 'current (' + activePath + ')';
		try{
			o.add(new Option(opt,activePath, true, true),null);
		}catch(e){
			o.add(new Option(opt,activePath, true, true));
		}
	}
	o.onchange = function(){
		$('path').value = this.options[this.selectedIndex].value;
	}
	//default path
	var opt = 'default';
	if(activePath == '/') opt += ' (active)';
	try{
		o.add(new Option(opt,'/'),null);
	}catch(e){
		o.add(new Option(opt,'/'));
	}
		
}
function topPos(){
	var ScrollTop = document.body.scrollTop;
	if (ScrollTop == 0){
	    if (window.pageYOffset)
	        ScrollTop = window.pageYOffset;
	    else
	        ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
	}
	return(ScrollTop);
}
function jumpTop(){
	var ScrollTop = document.body.scrollTop;
	if (ScrollTop == 0){
	    if (window.pageYOffset)
	        window.pageYOffset = 0;
	    else
	        if( document.body.parentElement) document.body.parentElement.scrollTop = 0;
	}else{
		document.body.scrollTop = 0;
	}
}
function getDocHeight() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
}
function startSlide(gallery, slide){
	curGallery = gallery;
	scroll(0,0);
	$('gallery-slide-back').style.visibility = 'visible';
	$('gallery-slide-back').style.display = 'block';
	$('gallery-slide-back').style.height = getDocHeight() +'px';
	$('gallery-slide').style.display = 'block';
	showSlide(slide);
}
function showSlide(slide){
	$('gallery-slide-img').src = gallery[curGallery]['path']+gallery[curGallery]['images'][slide]['image'];
	$('gallery-slide-title').innerHTML = gallery[curGallery]['images'][slide]['title'];
	$('gallery-slide-description').innerHTML = gallery[curGallery]['images'][slide]['description'];
	var w = $('gallery-slide-img').width;
	$('gallery-slide').style.left = ((window.innerWidth - w) /2) +'px';
	
}
