function GetRandom(start,end) 

{ 

    var range = end - start + 1; 

    var result = start + Math.floor(Math.random()*range); 

    return result;

}



function LoadRandom(the_div, images) 

{ 

  result = GetRandom(1,images);

  var image = new Array();

  image[0] = new Image();

  image[0].src = "images/" + the_div + "_" + result + ".jpg";

  var the_style, current, hiddenform;

    the_style = getStyleObject(the_div);

    hiddenform = document.getElementById('hiddenform');

    if (the_style != false)



  {

    the_style.background = "#ECE2C4 url(images/" + the_div + "_" + result + ".jpg) no-repeat 1px 1px";

    hiddenform.current.value = result; 

    changeBg2(result);

  }

  for (a=1;a<=images;a++)

  {

    image[a] = new Image();

    image[a].src = "images/" + the_div + "_" + a + ".jpg";

  } 

}



function changeBg(the_div)

{

  var the_style = getStyleObject(the_div);

  if (the_style != false)

  {

    the_style.background = "#D3D8E3";

  }

}



function changeBg2(the_div)

{

 var the_style, current, hiddenform;

    the_style = getStyleObject(the_div);

    hiddenform = document.getElementById('hiddenform');

    if (the_style != false)



  {


    hiddenform.current.value = the_div; 

  }

}



function getStyleObject(objectId) {

  if (document.getElementById && document.getElementById(objectId)) {

    return document.getElementById(objectId).style;

  } else if (document.all && document.all(objectId)) {

    return document.all(objectId).style;

  } else {

    return false;

  }

}





function changeMain(the_div, the_change) {

    var the_style, current, hiddenform;

    the_style = getStyleObject(the_div);

    hiddenform = document.getElementById('hiddenform');

    if (the_style != false) {

current = hiddenform.current.value;

    changeBg(current);

     the_style.background = "#ECE2C4 url(images/" + the_div + "_" + the_change + ".jpg) no-repeat 1px 1px";

    hiddenform.current.value = the_change;

    changeBg2(the_change);

  }

}



function next(the_div)

{

  var the_style, current, hiddenform;

  the_style = getStyleObject(the_div);

  if (the_style != false) {

current = hiddenform.current.value;

    if (current >= 15)

    {

	    changeBg(current);

	    the_change = 1;

	    changeMain(the_div,the_change);



    }

    else

    {

	    changeBg(current);

	    the_change = ++current;

	    changeMain(the_div,the_change);



    }  

  }

}



function previous(the_div)

{

  var the_style, current, hiddenform;

  the_style = getStyleObject(the_div);

  hiddenform = document.getElementById('hiddenform');

  

  if (the_style != false)

  {

    current = hiddenform.current.value;

    if (current-1 >= 1)

    {

	    changeBg(current);

	    the_change = current;

	    changeMain(the_div,the_change);

    }

    else

    {

	    changeBg(current);

	    the_change = 15;

	    changeMain(the_div,the_change);

    }    

  }

}










