Random insert and random rotation
<p>I'm inserting images inside a div in random order. </p>

<p>I would like to also rotate the images randomly. I have Jquery and a rotate-plugin for jquery that works simply by typing something like 
    $("#img").rotate(45);</p>

<p>Here is my code for the random order of the images:</p>

<pre><code>var contents=new Array (

'&lt;img class="karkki" class="omenalaku" src="images/omenalaku01.png"      onclick="image_control001();" alt="omenalaku" /&gt;',

'&lt;img class="karkki" class="omenalaku" src="images/omenalaku02.png" onclick="image_control002();" alt="omenalaku" /&gt;',

'&lt;img class="karkki" class="omenalaku" src="images/omenalaku03.png" onclick="image_control003();" alt="omenalaku" /&gt;',

'&lt;img class="karkki" class="omenalaku" src="images/omenalaku04.png" onclick="image_control004();" alt="omenalaku" /&gt;',

'&lt;img class="karkki" class="omenalaku" src="images/omenalaku05.png" onclick="image_control005();" alt="omenalaku" /&gt;',

'&lt;img class="karkki" class="omenalaku" src="images/omenalaku06.png" onclick="image_control006();" alt="omenalaku" /&gt;',

'&lt;img class="karkki" class="omenalaku" src="images/omenalaku07.png" onclick="image_control007();" alt="omenalaku" /&gt;',

'&lt;img class="karkki" class="omenalaku" src="images/omenalaku08.png" onclick="image_control008();" alt="omenalaku" /&gt;',

'&lt;img class="karkki" class="omenalaku" src="images/omenalaku09.png" onclick="image_control009();" alt="omenalaku" /&gt;',

'&lt;img class="karkki" class="omenalaku" src="images/omenalaku10.png" onclick="image_control010();" alt="omenalaku" /&gt;'
);

// insert elements in random order inside the candybox div
var i=0
//variable used to contain controlled random number 
var random

//while all of array elements haven't been cycled thru
while (i&lt;contents.length){
//generate random num between 0 and arraylength-1
random = Math.floor(Math.random()*contents.length)
    //if element hasn't been marked as "selected"
if (contents[random]!="selected"){
$(".candybox").append(contents[random]);
//mark element as selected
contents[random]="selected"
i++
}
}
</code></pre>

<p>Is it possible to insert the random rotation into the same while loop? My attempts resulted in every image having the same amount of rotation. I would like each image to have a different rotation value.</p>

<p>EDIT:</p>

<p>Here is myy feeble attempt:</p>

<pre><code>// insert elements in random order inside the candybox div
var i=0
//variable used to contain controlled random number 
var random

//while all of array elements haven't been cycled thru
while (i&lt;contents.length){
//generate random num between 0 and arraylength-1
random = Math.floor(Math.random()*contents.length);
randomrot = Math.floor(Math.random()*360);
//if element hasn't been marked as "selected"
if (contents[random]!="selected"){
$(".candybox").append(contents[random]);
contents[random].rotate(randomrot);
//mark element as selected
contents[random]="selected"
i++
}
}
</code></pre>

<p>This results in console error "Object  has no method 'rotate'. Seems like I'm trying to assing the rotate-plugin incorrectly to the dom element, but how to do it properly?</p>
