var AnimTimer = 0;
var front = 1;
var back = 2;
var curpic=1;
var nextpic=2;
var maxp=8;

$(document).ready(function(){
	onResize();
	$("#tswitch" + back).fadeOut();
	AnimTimer = window.setTimeout( "ToggleFrames()", 5000 );
	$(window).resize( onResize );
});

function onResize(){
	var w = $("#switcher").width();
	$("#switcher img").width( w - 54 );
	w = $('#layout').width();
	if($.browser.version == "6.0" && $.browser.msie){
		w-=54;
	}
	$("#theme").width( w );
}

function SwitchImages(){
	curpic = nextpic++;
	if( nextpic>maxp ){
		nextpic=1;
	}
	front = (front == 1 ? 2 : 1);
	back = (back == 1 ? 2 : 1);
	$("#tswitch" + back).css({'background-image' : 'url(/images/theme' + nextpic + '.jpg)'});
	AnimTimer = window.setTimeout( "ToggleFrames()", 5000 );
}

function ToggleFrames(){
	$("#tswitch" + front).fadeOut(2000);
	$("#tswitch" + back).fadeIn(2000, SwitchImages);
}