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

Utils.TopBoxHandler = {
	cache_key: 'topkinyilo',
	status: new Object(),
  bulvar_enable_div: 'bulvarOn',
  bulvar_disable_div: 'bulvarOff',

	IconStyle: '',

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

/* opens and hides a specified box */
	bulvarOn: function (){
		divs1=getElementsByClass('bulvar');
    for (i in divs1){
			if (typeof(divs1[i]) == 'object') {
				divs1[i].style.display = 'block';
			}
		}
		divs2=getElementsByClass('komoly');
    for (i in divs2){
			if (typeof(divs2[i]) == 'object') {
				divs2[i].style.display = 'none';
			}
		}
		Utils.TopBoxHandler.status['bulvar']='on';
		if (Utils.TopBoxHandler.enable_div) Utils.TopBoxHandler.enable_div.style.display = "none";
		if (Utils.TopBoxHandler.disable_div) Utils.TopBoxHandler.disable_div.style.display = "block";
		Utils.TopBoxHandler.saveState();
	},

	bulvarOff: function (){
		divs=getElementsByClass("bulvar");
    for (i in divs){
			if (typeof(divs[i]) == 'object') 
			divs[i].style.display = 'none';
		}
		divs=getElementsByClass('komoly');
    for (i in divs){
			if (typeof(divs[i]) == 'object') 
			divs[i].style.display = 'block';
		}
		Utils.TopBoxHandler.status['bulvar']='off';
		if (Utils.TopBoxHandler.enable_div) Utils.TopBoxHandler.enable_div.style.display = "block";
		if (Utils.TopBoxHandler.disable_div) Utils.TopBoxHandler.disable_div.style.display = "none";
		Utils.TopBoxHandler.saveState();
	},
	showHideBox: function (id,dont_set,forcestate){
  	div1=document.getElementById('place_controller_'+id);
  	div2=document.getElementById('place_topcontent_'+id);
  	div3=document.getElementById('place_topcontent_bulvar_'+id);
  	div4=document.getElementById('place_topcontent_komoly_'+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";
      if (div3) div3.style.display="block";
			if (div4) div4.style.display="block";
			element.innerHTML='<img src="http://img.hirkereso.hu/img/skin/default/doboz/kevesebb.jpg"  border="0" style="padding: 2px 0pt 0pt;">';
			Utils.TopBoxHandler.status[id]=1;
  	}else{
			div2.style.display="none";
			if (div3) div3.style.display="none";
			if (div4) div4.style.display="none";
			Utils.TopBoxHandler.status[id]=0;
			element.innerHTML='<img src="http://img.hirkereso.hu/img/skin/default/doboz/tobb.jpg"  border="0" style="padding: 2px 0pt 0pt;">';
  	}
  	if (!dont_set) Utils.TopBoxHandler.saveState(id,new_state);
	},

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

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

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

	onLoad: function(ok,data) {

    var enable_div = document.getElementById(Utils.TopBoxHandler.bulvar_enable_div);
    var disable_div = document.getElementById(Utils.TopBoxHandler.bulvar_disable_div);
		Utils.TopBoxHandler.enable_div=enable_div;
		Utils.TopBoxHandler.disable_div=disable_div;
		var string;
		if (typeof data == 'object' && data != 'null' && data != undefined) { 
			string = data.value; 
		} 
		else { 
			string = data; 
		} 
		if (string == 'null' || string == undefined){ 
            Utils.TopBoxHandler.bulvarOff();
			return false;
		}

			Utils.TopBoxHandler.status=JSON.parse(string);
		for (var id in Utils.TopBoxHandler.status){
			if(isInt(id)){
				Utils.TopBoxHandler.showHideBox(id,1,Utils.TopBoxHandler.status[id]);
			}else{
				if (id == 'bulvar'){
					if (Utils.TopBoxHandler.status[id] == 'on'){
						Utils.TopBoxHandler.bulvarOn();
					}else{
						Utils.TopBoxHandler.bulvarOff();
					}
				
				}
			}
		}
		if (!Utils.TopBoxHandler.status['bulvar']){
			Utils.TopBoxHandler.bulvarOff();
		}
		return;
  }
};

