Event.observe(window,"load",function(){
	
	if(typeof jQuery != "undefined")jQuery.noConflict();
	
	//Create entry edit button
	$$(".cms_hidden_entry_id").each(function(element){
		element.onclick = function(){
			var entryId = this.getAttribute("entryid");
			var blockLabelId = this.getAttribute("blocklabelid");
			if(entryId != null && entryId > 0){
				common_to_layer(EntryEditPage+"/"+entryId,{width:800,height:600});
			}else{
				common_to_layer(EntryEditPage+"/addlabeldentry_"+blockLabelId,{width:800,height:600});
			}
		}
	});
	
	common_element_to_layer($("soy_cms_operation"),{
		targetId:'soy_cms_operation_frame',
		width:300,
		height:230,
		onclose:function(){
			return false;	
		},
		disableClose : true
	});
	$("soy_cms_operation").style.width = "100%";
	$("soy_cms_operation").style.height = "100%";
	$("soy_cms_operation").show();
	
	//Toggle entry edit button
	$("soy_cms_operation_toggle_edit_entry_button").onclick = function(){
		if(!this.checked){
			$$(".cms_hidden_entry_id").each(function(element){
			    element.hide();
		  	});
		}else{
			$$(".cms_hidden_entry_id").each(function(element){
			    element.show();
		  	});
		}
	}
	
	//Toggle display draft entry or not
	$("soy_cms_operation_toggle_show_entry_button").onclick = function(){
		
		var search = location.search.toQueryParams();
		
		if(this.checked){
			search.show_all = 1;
		}else{
			search.show_all = 0;
		}
		
		window.location.search = "?" + $H(search).toQueryString();
	};
	
	if($("soy_cms_operation_toggle_show_entry_button").checked){
		$$("a").each(function(ele){
			var tmp = ele.innerHTML;//for IE
			if(ele.href.indexOf("?") != -1){
				ele.href += "&show_all=1";
			}else{
				ele.href += "?show_all=1";
			}
			ele.innerHTML = tmp;//for IE
		});
	}
	
	//Template edit button
	if($("soy_cms_operation_edit_template_form")){
		$("soy_cms_operation_edit_template_form").action = templateEditAddress;
		$("soy_cms_operation_edit_template_form").onsubmit = function(){
			return common_submit_to_layer(this,{width:800,height:600,onclose:function(){location.reload();}});
		};
	}
	
	
});