/**
* Released under the terms or MIT license:
*
* Copyright (c) Bajcic Dragan
* 
* Permission is hereby granted, free of charge, to any person obtaining a copy 
* of this software and associated documentation files (the "Software"), to deal 
* in the Software without restriction, including without limitation the rights 
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
* copies of the Software, and to permit persons to whom the Software is 
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all 
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
* SOFTWARE.
*/

var mst = Class.create();
mst.prototype = {
  initialize: function(staff_tabs_container,staff_tabs_class) {
		
		this.bgcolor='#ffffff';
		this.activeColor='#ffffff';
		this.stc=staff_tabs_container;
		this.stbClass=staff_tabs_class;
		this.elms = $(staff_tabs_container);
		
		new Insertion.Top(this.elms,'<div id="staff_tab-bar"></div>');

		this.staff_tabs = $$(staff_tabs_class);
		this.clear(this.staff_tabs);

		MST=this;
  },
	
	clear: function(staff_tabs){
		staff_tabs.each(function(elms){
			elms.setStyle({display:'none'});
		});
	},
	
	makeActive: function(staff_tab_id){
		
		$(staff_tab_id).setStyle({display:'block'});
		$('mst-'+staff_tab_id).setStyle({backgroundColor:MST.activeColor});
		$$('div.mst-staff_tab').each(function(elms){
		if(elms.hasClassName('mst-staff_tab-active')){

				elms.removeClassName('mst-staff_tab-active');
				elms.setStyle({backgroundColor:MST.bgcolor});
			}
		
		});
		$('mst-'+staff_tab_id).addClassName('mst-staff_tab-active');
	},
	
	addTab: function(staff_tab_id,text,img){
		
		new Insertion.Bottom($('staff_tab-bar'),'<div id="mst-'+staff_tab_id+'" class="mst-staff_tab"><h5 class="staff_tab">'+text+'</h5><img src="/rsstatic/main/animeResources/staffPicks/images/'+img+'"></div>');
		var elmnt=$('mst-'+staff_tab_id);
		elmnt.setStyle({backgroundColor:this.bgcolor});
		
		Event.observe(elmnt, 'click', function() {

			window.mst.prototype.clear(MST.staff_tabs);
			window.mst.prototype.makeActive(staff_tab_id,MST.staff_stbClass);
		});
		
		Event.observe(elmnt, 'mouseover', function(nn) {
			
			if(!elmnt.hasClassName('mst-staff_tab-active')){
			elmnt.setStyle({backgroundColor:MST.activeColor});
			}
		});
		
		Event.observe(elmnt, 'mouseout', function(nn) {

			if(!elmnt.hasClassName('mst-staff_tab-active')){
			elmnt.setStyle({backgroundColor:MST.bgcolor});
			
			}
		
		});
	
	},
	
	
	removeTabTitles: function(staff_tabTitlesClass){
			this.staff_tabsTitles = $$(staff_tabTitlesClass);
			this.staff_tabsTitles.each(function(elms){
				elms.setStyle({display:'none'});
			});
	}
};

document.observe('dom:loaded' , function(){
										var StaffTabs= new mst('staffTabs','div.staff_tab');
										StaffTabs.removeTabTitles('h5.staff_tab_title');
										StaffTabs.addTab('st1','Staff Tab 1','image1.gif');
										StaffTabs.addTab('st2','Staff Tab 2','image2.gif');
										StaffTabs.addTab('st3','Staff Tab 3','image3.gif');
										StaffTabs.makeActive('st'+ (randomnumber=Math.floor(Math.random()*3+1)));
										});