
function get_rnd(max)
{
	return Math.ceil(Math.random()*max);
}

function swap_random_pic()
{
	while(swap_id==swap_prev)
		swap_id = get_rnd(12);

	while(in_array(new_pic, imgs))
		new_pic = get_rnd(51);

	$("#p"+swap_id).ImageSwitch({NewImage:"cache/143x143/header_fotos/p"+new_pic+".jpg"});
	
	imgs[swap_id-1] = new_pic;
	swap_prev = swap_id;
	
	setTimeout('swap_random_pic()', 1100+get_rnd(1000));
}

function cycle_pic()
{
	swap_id++;
	if (swap_id>imgs.length) swap_id = 0;
	$("#p1").ImageSwitch({NewImage:"cache/858x286/"+imgs[swap_id]});
	setTimeout('cycle_pic()', 4000);
}


function in_array (needle, haystack, argStrict) {
    var key = '', strict = !!argStrict;
    if (strict) {
        for (key in haystack) {
            if (haystack[key] === needle) {
                return true;
            }
        }
    } else {
        for (key in haystack) {
            if (haystack[key] == needle) {
                return true;
            }
        }
    }
    return false;
}
