var imgs = {}

imgs.init = function(){
	imgs.objs = $('.main_imgs .imgs img');
	imgs.holder = $('.main_imgs .imgs');
	imgs.links = $('.main_imgs .links a');
	
	if (imgs.objs.length < 1) return false;
	
	for(var i = 0 ; i < imgs.objs.length ; i++){
		imgs.objs[i] = $(imgs.objs[i]).css({"position":"absolute", "left":0, "top":0});
		imgs.links[i].i = i;
	}
	
	imgs.current = 0 ;
	imgs.objs.max = imgs.objs.length - 1;
	
	imgs.set(0);
	$(imgs.links[0]).parent().addClass('current');
	
	imgs.timer = window.setInterval(imgs.setRand, 3000);
	
	$('.main_imgs .links a').mouseover(function(){
		imgs.set(this.i);
		window.clearInterval(imgs.timer);
	});
}

imgs.set = function(i, link){
	if (i==imgs.current) {
		return false;
	}
	imgs.prev = imgs.current;
	imgs.current = i;
	imgs.objs[imgs.current].appendTo(imgs.holder).css("opacity", 0).animate({"opacity": 1}, "fast");
	$(".main_imgs .links div div").removeClass("current");
	$(imgs.links[i]).parent().addClass('current');
}

imgs.setRand = function() {
	imgs.set(Math.round(Math.random()*imgs.objs.max));
}

function Staff(obj) {
	this.current=0;
	this.images = obj.find('.images div img');
	var i;
	for (i=0 ; i<this.images.length ; i++){
		this.images[i] = $(this.images[i]);
	}
	
	if(i==0) return false;
	
	this.texts = obj.find('.texts div');
	for (i=0 ; i<this.texts.length ; i++){
		this.texts[i] = $(this.texts[i]);
	}
	
	this.enter(Math.floor(Math.random()*this.images.length));
}

Staff.prototype.enter = function(i){
	this.images[this.current].css('display','none');
	this.texts[this.current].css('display','none');
	this.current = i;
	this.images[this.current].css('display','block');
	this.texts[this.current].css('display','block');
}
Staff.prototype.leave = function(i){
	
}

$(window).load(function(){	
	imgs.init();
	
	var oStaff = new Staff($('.staff'));
	
	$('.staff area').mouseenter(function(){
		oStaff.enter(this.href.match(/#(\d+)/)[1]);
		this.style.zIndex='1000';
	});
	$('.staff area').mouseleave(function(){
		oStaff.leave(this.href.match(/#(\d+)/)[1]);
		this.style.zIndex='';
	});
	
	
});

/* this is for beautification of a left side form */
function areaOnFocus(element, inputText)
{    if(element.value == inputText)
     {
          element.value='';
		  element.style.backgroundColor="white";
		  element.style.color="black";
     }
}
function areaOnBlur(element, inputText)
{
     if(element.value=='')
     {
          element.value = inputText;
		  element.style.backgroundColor="lavender";
		  element.style.color="grey";
     }	
}
