	var listImg = new Array("img/h1.jpg","img/h2.jpg","img/h3.jpg","img/h4.jpg");
	var listColor = new Array("#fffedf","#414141","#fffedf","#414141");
    var auto =true;
    var nextpic=1;
    var front=1;
    var back=2;
    var maxp=4;
	$(document).ready(function(){

		AnimTimer = window.setTimeout( "ToggleFrames()", 5000 );

	});

	function SwitchImages(){
		curpic = nextpic;

		front = (front == 1 ? 2 : 1);
		back = (back == 1 ? 2 : 1);
		//alert("cur = " + curpic + " \n next =" + nextpic + " \n ");

        back='';
			$("#tswitch" + back).delay(1000).css({'background-image' : 'url(' + listImg[nextpic-1] + ')'});
			$("#menu a").css({'color' : listColor[nextpic-1]});
		nextpic++;
		if( nextpic > maxp ){
			nextpic=1;
		}

		if(auto){
			AnimTimer = window.setTimeout( "ToggleFrames()", 5000 );
		} else {
			window.clearTimeout(AnimTimer);
		}

		//alert("cur 1 = " + curpic + " \n next 1 =" + nextpic + " \n ");

	}

	function ToggleFrames(){

		$("#tswitch").fadeTo(1000,0.1,SwitchImages);
//		$("#menu a").css({'color' : '#000'});
		$("#tswitch").fadeTo(1000,1);


	}

	function changeBG(i){

		auto = false;
		window.clearTimeout(AnimTimer);
		window.clearTimeout(AnimTimer);
		//curpic = i - 1;
		nextpic = i;

		front = (front == 1 ? 2 : 1);
		back = (back == 1 ? 2 : 1);

		$(".bgText").hide()

		$("#bgText" + (nextpic)).show();

		$("#menu a").css({'color' : listColor[nextpic-1]});
		$("#tswitch").css({'background-image' : 'url(' + listImg[nextpic-1] + ')'});


		ToggleFrames();

	}

