var headline_count1;
var headline_howmany1 = 0;
var headline_interval1;
var old_headline1 = -1;
var current_headline1 = 0;

var array_count;

var arraytest;
shuffle = function(o){
    for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
    return o;
};
arraytest = [0,1,2,3,4,5,12,7,8,9,10,11];
imagesDisplayed = [0,1,2,3,4,5,6];

shuffle(arraytest);
shuffle(imagesDisplayed);

$(document).ready(function(){
	//$("div#randompictures").src=('../images/random/1.png');
	var picture_src = '';
	for (var i = 0;i < 7; i++){
		picture_src = picture_src + "<div id="+ arraytest[i] +"><img class=rPictures src='images/random/" + arraytest[i] + ".png' width='108' height='108' border='0' alt=''></div>";
	};

	array_count = i;


	$("#randompictures").html(picture_src);
	$("img.rPictures").hide();

	headline_count1 = $("img.rPictures").size();
	
	$("img.rPictures").toggle();
	headline_rotate1();
	//$("img.rPictures").fadeIn(7000);

  	headline_interval1 = setInterval(headline_rotate1,5200);

	
});

function headline_rotate1() {
    //current_headline1 = (old_headline1 + 1) % headline_count1;

	
	//current_headline1 = parseInt(Math.random() * 7);
	current_headline1 = (old_headline1 + 1) % headline_count1;
	
	var current_headline2 = imagesDisplayed[current_headline1];
	var old_headline2 = imagesDisplayed[old_headline1];
    $("img.rPictures:eq(" + old_headline2 + ")").fadeTo(5000,1);
    $("img.rPictures:eq(" + current_headline2 + ")").fadeTo(5000,0, function(){
		var grab_another =arraytest[array_count];
		array_count++;
		if (array_count > 11){
			array_count =0;
		};
		var pic = "images/random/" + grab_another + ".png";
		$("img.rPictures:eq(" + current_headline2 + ")").attr({src: pic});
	});
    old_headline1 = current_headline1;
	headline_howmany1++;	
	
}

