$(document).ready(function() {

    var MCtimer = window.setTimeout(function() { shift(); }, 0);

  		$('#head1').html(pole[0][1]).attr('href',pole[0][0]);
  		$('#head2').html(pole[1][1]).attr('href',''+pole[1][0]);
  		$('#head3').show().html(pole[2][1]).attr('href',pole[2][0]);
  		$('#head4').show().html(pole[3][1]).attr('href',pole[3][0]);
		$('#head5').show().html(pole[4][1]).attr('href',pole[4][0]);

  		$('#head2').hide();
  		$('#head3').hide();
  		$('#head4').hide();
  		$('#head5').hide();

	function shift() {
		if(index == 1){
			$('#head5')
				.hide();
			$('#imgFoto5')
  				.attr('class','imgRight').attr('src','images/5.gif');
		}

		$('#newsImage')
  			.attr('src', pole[index-1][2])
  			.fadeIn('slow');

  		$('#newsImg').attr('href',pole[index-1][0]);

  		$('#head' + (index-1))
			.hide();

  		$('#head' + (index))
  			.show()

  		$('#imgFoto' + index)
  			.removeAttr('class');
  		$('#imgFoto' + index)
  			.attr('src','images/' + index + '-active.gif');


  		$('#imgFoto' + (index-1))
  			.attr('class','imgRight').attr('src','images/' + (index-1) + '.gif');

  		index++;

		if(index == 6){
			index = 1;
		}


        MCtimer = window.setTimeout(function() { shift(); }, MCtime );
	}


    $('#button1').click(function() {
    	index = 1;
		clicked(index);
    });

    $('#button2').click(function() {
    	index = 2;
		clicked(index);
    });

    $('#button3').click(function() {
    	index = 3;
		clicked(index);
    });

    $('#button4').click(function() {
    	index = 4;
    	clicked(index);

    });

    $('#button5').click(function() {
    	index = 5;
		clicked(index);
    });

    function clicked(index) {

		var i;
	    for(i=1;i<=5;i++)
	    {
	    	if(i == index)
	    	{
	    		$('#imgFoto' + index)
	  				.removeAttr('class')
	  				.attr('src','images/' + index + '-active.gif');

	  			$('#newsImage')
	  				.attr('src', pole[index-1][2])
	  				.fadeIn('slow');

	  			$('#newsImg').attr('href',pole[index-1][0]);

				$('#head' + index)
	  				.show()
	    	}
			else
			{
	  			$('#head' + i)
					.hide();

				$('#imgFoto' + i)
	  				.attr('class','imgRight')
	  				.attr('src','images/' + i + '.gif');

	  		}

	  	}

    }


/*    $('#button1,#button2,#button3,#button4,#button5,#head1,#head2,#head3,#head4,#head5').mouseover(function() {
   		window.clearTimeout(MCtimer);
    });

    $('#button1,#button2,#button3,#button4,#button5,#head1,#head2,#head3,#head4,#head5').mouseout(function() {
        MCtimer = window.setTimeout(function() { shift(); }, MCtime);
    });*/

});
