// JavaScript Document

$(document).ready(init);
$(window).load(init2);

var int = 500;
var fn = 0;
var fthis;
var frames = new Array;
var framesp = new Array;

function init() {
	$('.nav a').hover(fin,fout);
	$('.active').css({opacity:.7});
	if($('.archive').length) {
		$('.archive select').change(function(){
			$('.year').addClass('hidden');
			$('#'+$(this).val()).removeClass('hidden');
		});
		$('.year').addClass('hidden');
		$('#'+$('.archive select').val()).removeClass('hidden');
	}
}

function makeframes() {
	fw = 0;
	fthis = 0;
	$('.slide').each(function(){
		fw = fw + $(this).children('img').width() + 5;
		$(this).hover(fhov,fhov).css({width:$(this).children('img').width()});
		$('.slides').css({'width':fw,});
		frames[fn] = $(this);
		framesp[fn] = $(this).position().left;
		fn++;
	});
	$('.frame-l').hover(fin,fout).click(frameleft);
	$('.frame-r').hover(fin,fout).click(frameright);
}

function init2() {
	if ($('.rotator-wrap').length) {
		makeframes();
	}
}

function fin() {
	$(this).css('opacity',.7);
}
function fout() {
	if(!$(this).hasClass('active')) $(this).css('opacity',1);
}
function fhov(){
	$(this).children('.active').toggleClass('hidden');
}

function frameleft() {
	if ( 0 < fthis) {
		fthis--;
	} else {
		fthis = fn - 1;
	}
	move();
}
function frameright() {
	if (fthis < fn - 1) {
		fthis++;
	} else {
		fthis = 0;
	}
	move();
}

function move() {
	$('.slides').stop().animate({'left':-framesp[fthis]},int);
}
