Event.observe(window, 'load', init, false);
		
function init() {
	Lightbox.init();
}

var LangTextTabs = {
  cur_lang: '',
  
	init: function(lang) {
		this.cur_lang = lang;
	},  
  
  open: function(lang) {
    this.cur_lang = $('cur_lang').innerHTML;
    if (lang != this.cur_lang) {
      $('lang_tab_link_'+lang).addClassName('current');
      //alert('lang_tab_link_'+lang);
      $('lang_tab_link_'+this.cur_lang).removeClassName('current');
      $('lang_tab_'+lang).show();
      $('lang_tab_'+this.cur_lang).hide();     
      $('cur_lang').innerHTML = lang;
    }
  }
  
}

var Settings = {
  cur_tab: 'pages',
  sect_names: ['pages', 'layouts', 'sections', 'containers', 'tags', 'languages'],

  new_link: function(url, msg) {
    this.box_loading_msg(msg);
    Lightbox.showBoxByAJAX(url, 500, 700);
  },
  
  edit_link: function(url, name, id, msg) {
    //new Ajax.Updater('settings_actions', url, {asynchronous:true, evalScripts:true, onComplete:function(request){Element.hide(name+'_indicator_'+id)}, onLoading:function(request){Element.show(name+'_indicator_'+id)}}); 
    /*myLightWindow.activateWindow({
    	href: url, 
    	title: 'Waiting for the show to start in Las Vegas'
    });*/
    this.box_loading_msg(msg);
    Lightbox.showBoxByAJAX(url, 500, 700);
  },
  
  element_edit_link: function(url, name, id, msg) {
    //new Ajax.Updater('settings_actions', url, {asynchronous:true, evalScripts:true, onComplete:function(request){Element.hide(name+'_indicator_'+id)}, onLoading:function(request){Element.show(name+'_indicator_'+id)}}); 
    /*myLightWindow.activateWindow({
    	href: url, 
    	title: 'Waiting for the show to start in Las Vegas'
    });*/
    this.box_loading_msg(msg);
    Lightbox.showBoxByAJAX(url, 750, 700);
  },  
  
  box_loading_msg: function(msg) {
    $('boxContents').innerHTML = '<img src="/images/admin/loading.gif"> '+msg;
  },

  delete_link: function(url, name, id) {
      new Ajax.Request(url, {asynchronous:true, evalScripts:true, onComplete:function(request){Element.hide(name+'_'+id)}, onLoading:function(request){Element.show(name+'_indicator_'+id)}}); 
  }, 

  list_link: function(url, name) {
    new Ajax.Updater('settings_content', url, {asynchronous:true, evalScripts:true, onComplete:function(request){Element.hide('tab_indicator')}, onLoading:function(request){Element.show('tab_indicator')}}); 
    $('tab_'+this.cur_tab).removeClassName('current');
    $('tab_'+name).addClassName('current');
    this.cur_tab = name;
  },
  
	show_section_existing_element_field: function() {
		$('existing_element_for_section').show();
		$('new_element_for_section').hide();
	},
	
	show_section_new_element_field: function() {
		$('existing_element_for_section').hide();
		$('new_element_for_section').show();
	},	
  
	init: function() {
		for(name in this.sect_names) {
			this.sections[name] = [];
		}
		this.cur_item = '';
		this.cur_section = '';
		this.cur_msg = '';
		this.cur_inv = '';
	},


	clear: function() {
		for(i=0;i<this.sect_names.length;i++) {
			name = this.sect_names[i];
			//alert(name);
			if ($('view_n_'+name)) {
				Element.hide('view_all_'+name); 
				Element.hide('view_n_'+name);
			}
			Element.hide(name);
			if (this.sections[name].length == 1) {
				the_item = this.sections[name].first();
				//alert(this.sections[name].first());
				if ($(the_item)) {
					Element.hide(the_item);
				}
				if ($(the_item+'_opened')) {
					Element.hide(the_item+'_opened');
				}
				if ($(the_item+'_closed')) {
					Element.hide(the_item+'_closed');
				}
			}
			this.sections[name] = [];
		}
		this.cur_item = '';
		this.cur_section = '';
		this.cur_msg = '';
		this.cur_inv = '';
	},

  get_size: function() {
	var all_size = 0;
	for(i=0;i<this.sect_names.length;i++) {
		name = this.sect_names[i];
		//alert(this.counters[name]);
		all_size += this.sections[name].length;
		//all_size += this.counters[name];
	}
	return all_size;
  },
  
  get_inv_size: function() {
		return this.sections['invitation_new'].length+this.sections['invitation_accepted'].length+this.sections['invitation_declined'].length
  },  
	
  add: function(section, item) {
 		this.sections[section].push(item);
  },
  
  remove: function(section, item) {
 		this.sections[section] = this.sections[section].without(item);
  },  
  
  set_section: function(section, items) {
  	this.sections[section] = items;
  },
  
  is_first: function(section, item) {
  	if (this.sections[section].first() == item) {
  		return true;
  	} else {
  		return false;
  	}
  },
  
  is_last: function(section, item) {
  	if (this.sections[section].last() == item) {
  		return true;
  	} else {
  		return false;
  	}
  }  
  
}
