var in_trans = false, rel, other;
var it2 = false, curp = 1;
$(function(){
	$('#main_image').nivoSlider();

	//Staff page
	$('#sw_cont a').click(function(){
		if(in_trans || $(this).hasClass('c_active'))
			return false;
		rel = $(this).attr('rel');
		other = rel == '#bio' ? '#resume' : '#bio';

		$('#sw_cont a').removeClass('c_active');
		$(this).addClass('c_active');
		
		in_trans = true;
		$(other).hide(300, function(){
			$(rel).show(300, function(){
				in_trans = false;
			});
		});

		return false;
	});

	//Lightbox
	$('a[rel=lightbox]').lightBox();
	$('#instr_scroll .instr_s').each(function(){
		$(this).click( get_stf($(this).attr('rel')) );
	})
	$('#instr_l').click(function(){
		scroll_thumbs(curp - 1);
	})
	$('#instr_r').click(function(){
		scroll_thumbs(curp + 1);
	})

	//Contact
	$('select').change(function(){
		var id = '#' + $(this).attr('id') + '_val';
		var v = $(this).attr('value')
		$(id).attr('value', v);
	});
	$('#callback_form .text')
		.bind('focus', function(){
			if(this.value == $(this).attr('_def'))
				this.value = '';
		})
		.bind('blur', function(){
			if(this.value == '')
				this.value = $(this).attr('_def');
		})
	$('#callback_form').submit(function(){
		chk = ['type', 'message', 'name', 'email', 'phone'];

		for(i = 0; i < chk.length; i++){
			v = $('#' + chk[i]).attr('value');
			d = $('#' + chk[i]).attr('_def');
			if(v == '' || v == d){
				alert('All fields are required!');
				return false;
			}
		}
		return true;
	})
})
function get_stf(p){
	return function(){
		scroll_thumbs(p);
	}
}
function scroll_thumbs(page){
	if(it2)
		return;
	curp = page;
	if(curp < 1)
		curp = 1;
	if(curp > 3)
		curp = 3;
	var l = (curp - 1) * 320;
	it2 = true;
	$('#thumbs_in').animate({left : '-' + l + 'px'}, 300, 'linear', function(){ it2 = false; });
}
