if (!window.Utils) Utils ={};

Utils.BoxHandler = {
	cache_key: 'dobozok',
	status: new Object(),
	IconStyle: '',

	setIconStyle: function (style) {
		Utils.BoxHandler.IconStyle='-' + style;
	},

/* opens and hides a specified box */
	showHideBox: function (id,dont_set,forcestate){
  	div1=document.getElementById('place_controller_'+id);
  	div2=document.getElementById('place_content_'+id);

  	if (!div1 || !div2) return;
  	element=div1.getElementsByTagName('a')[0];
  	default_value=div1.getAttribute('default_value');
// doboz bekapcsolasa
  	var new_state ;
  	if (forcestate == 0 || forcestate == 1){
   		new_state=forcestate;
  	}else{
    	if (div2.style.display == 'none'){
      	new_state = 1;
    	}else{
      	new_state = -1;
    	}
  	}

  	if (new_state == 1){
      div2.style.display="block";
      element.innerHTML='<img src="http://img.hirkereso.hu/img/skin/default/doboz/becsuk.jpg"  border="0" style="padding: 2px 0pt 0pt;">';
			Utils.BoxHandler.status[id]=1;
  	}else{
    	div2.style.display="none";
			Utils.BoxHandler.status[id]=0;
    	element.innerHTML='<img src="http://img.hirkereso.hu/img/skin/default/doboz/kinyit.jpg"  border="0" style="padding: 2px 0pt 0pt;">';
  	}
  	if (!dont_set) Utils.BoxHandler.saveState(id,new_state);
	},

/* save the status of the id into a persistent storage */

	saveState: function(id,value){
		Store.save(Utils.BoxHandler.cache_key,JSON.stringify(Utils.BoxHandler.status));
		return;
	},

/* runs at pageload and displays the boxes in the correct state */

	onLoad: function(ok,data) {

		if (!data){
			return;
		}
		if (data.value){
			data=data.value;
		}

			Utils.BoxHandler.status=JSON.parse(data);
		
		for (var id in Utils.BoxHandler.status){
			Utils.BoxHandler.showHideBox(id,1,Utils.BoxHandler.status[id]);
		}
		return;
  }
};

