$(document).ready(function(){
	var x=0;
	var temp;
	timed=window.setInterval(headchange, 5000);
	$('.nextset').click (function () {
		clearInterval(timed);
		timed=window.setInterval(headchange, 5000);
		if (x == 3) {
			x = 1;
		} else {
			x++;
		}
		temp = '#text' + x;
		if ($(temp).length > 0) {
			$('#last8').html($(temp).html());
		}
		$('.lcont').hover(function (){
            $(this).addClass('selected');
        }, function (){
            $(this).removeClass('selected')
        });
		$(".lcont").click(function(){
				// $('.hd img').attr("src", $('img', this).attr("src"));
				$('.hd').html($(this, '.hcont').html() );
		// $('.hd div p').text($('a .htext', this).text() );
		});
	});
	$('.prevset').click (function () {
		clearInterval(timed);
		timed=window.setInterval(headchange, 5000);
		if (x == 1) {
			x = 3;
		} else {
			x--;
		}
		temp = '#text' + x;
		if ($(temp).length > 0) {
			$('#last8').html($(temp).html());
		}
		$('.lcont').hover(function (){
            $(this).addClass('selected');
        }, function (){
            $(this).removeClass('selected')
        });
		$(".lcont").click(function(){
				// $('.hd img').attr("src", $('img', this).attr("src"));
				$('.hd').html($(this, '.hcont').html() );
		// $('.hd div p').text($('a .htext', this).text() );
		});
	});
	function headchange() {
		if (x == 3) {
			x = 1;

		} else {
			x++;
		}
		temp = '#text' + x;
		if ($(temp).length > 0) {	
			$('#last8').html($(temp).html());
		}
        var old = '#none';
        $('.lcont').hover(function (){
            $(this).addClass('selected');
        }, function (){
            $(this).removeClass('selected')
        });
		$(".lcont").click(function(){
				// $('.hd img').attr("src", $('img', this).attr("src"));
				$('.hd').html($(this, '.hcont').html() );
		// $('.hd div p').text($('a .htext', this).text() );
		});


	}
	
	headchange();
});
