//really not important (the first two should be small for Opera's sake)
PositionX = 10;
PositionY = 10;
defaultWidth  = 600;
defaultHeight = 400;

//kinda important
var AutoClose = true;

//don't touch
function popImage(imageURL,imageTitle){
  var imgWin = window.open('','_blank','scrollbars=no,resizable=1,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY);
  if( !imgWin ) { return true; } //popup blockers should not cause errors
  imgWin.document.write('<html><head><title>'+imageTitle+'<\/title><script type="text\/javascript">\n'+
    'function resizeWinTo() {\n'+
    'if( !document.images.length ) { document.images[0] = document.layers[0].images[0]; }'+
    'var oH = document.images[0].height, oW = document.images[0].width;\n'+
    'if( !oH || window.doneAlready ) { return; }\n'+ //in case images are disabled
    'window.doneAlready = true;\n'+ //for Safari and Opera
    'var x = window; x.resizeTo( oW + 200, oH + 200 );\n'+
    'var myW = 0, myH = 0, d = x.document.documentElement, b = x.document.body;\n'+
    'if( x.innerWidth ) { myW = x.innerWidth; myH = x.innerHeight; }\n'+
    'else if( d && d.clientWidth ) { myW = d.clientWidth; myH = d.clientHeight; }\n'+
    'else if( b && b.clientWidth ) { myW = b.clientWidth; myH = b.clientHeight; }\n'+
    'if( window.opera && !document.childNodes ) { myW += 16; }\n'+
    'x.resizeTo( oW = oW + ( ( oW + 200 ) - myW ), oH = oH + ( (oH + 200 ) - myH ) );\n'+
    'var scW = screen.availWidth ? screen.availWidth : screen.width;\n'+
    'var scH = screen.availHeight ? screen.availHeight : screen.height;\n'+
    'if( !window.opera ) { x.moveTo(Math.round((scW-oW)/2),Math.round((scH-oH)/2)); }\n'+
    '}\n'+
    '<\/script>'+
    '<\/head><body onload="resizeWinTo();"'+(AutoClose?' onblur="self.close();"':'')+'>'+
    (document.layers?('<layer left="0" top="0">'):('<div style="position:absolute;left:0px;top:0px;display:table;">'))+
    '<img src="'+imageURL+'" alt="Loading image ..." title="" onload="resizeWinTo();">'+
    (document.layers?'<\/layer>':'<\/div>')+'<\/body><\/html>');
  imgWin.document.close();
  if( imgWin.focus ) { imgWin.focus(); }
  return false;
}

function fillLists() { 
// this function is used to fill the drop down lists on load

//
//Delivery Methods
//
addOption(document.ordering.deliverymethod, "Postage (cost will be confirmed)", "Postage (cost will be confirmed)");
addOption(document.ordering.deliverymethod, "Market collection", "Market collection");
addOption(document.ordering.deliverymethod, "Charged Delivery Request", "Charged Delivery Request");
addOption(document.ordering.deliverymethod, "Free Delivery Request (VIC-see delivery pg)", "Free Delivery Request (VIC-see delivery pg)");

//
//Payment Methods
//
addOption(document.ordering.paymentmethod, "Bank EFT (details will be provided)", "Bank EFT (details will be provided)");
addOption(document.ordering.paymentmethod, "PayPal", "PayPal");
addOption(document.ordering.paymentmethod, "Credit Card (info to be provided)", "Credit Card (info to be provided)");
addOption(document.ordering.paymentmethod, "Cash on delivery", "Cash on delivery");
addOption(document.ordering.paymentmethod, "Gift Voucher", "Gift Voucher (complete details ->)");
addOption(document.ordering.paymentmethod, "Cheque (details will be provided)", "Cheque (details will be provided)");

//
//Categories
//
for(i=1;i<=5;i++) {
  var category_id=document.getElementsByName("category" + i);

  addOption(category_id[0], "Mirrored Jewellery Cabinets", "Mirrored Jewellery Cabinets");
  addOption(category_id[0], "Bangle Stands", "Bangle Stands");
  addOption(category_id[0], "Necklace Stands", "Necklace Stands");
  addOption(category_id[0], "Earring Holders - Ornate Range", "Earring Holders - Ornate Range");
  addOption(category_id[0], "Earring Holders - Contemporary Range", "Earring Holders - Contemporary Range");
  addOption(category_id[0], "Earring Holders - Wood Collection", "Earring Holders - Wood Collection");
  addOption(category_id[0], "Earring Holders - Extra Large & Other designs", "Earring Holders - Extra Large & Other designs");
  addOption(category_id[0], "Cabinet Hangers & Display Stands", "Cabinet Hangers & Display Stands");
}
}


function SelectCode(id) {
// on change of category this function will work


var code_id=document.getElementsByName("code" + id);
var category_id=document.getElementsByName("category" + id);

removeAllOptions(code_id[0]);

addOption(code_id[0], "", "---Item code---");

if(category_id[0].value == 'Mirrored Jewellery Cabinets') {
  addOption(code_id[0], "Custom - Please advise details in the notes box below", "Custom - Please advise details in the notes box below");
  addOption(code_id[0], "Option 1 (Hooks Only)", "Option 1 (Hooks Only)");
  addOption(code_id[0], "Option 2 (Mesh Only - Fixed)", "Option 2 (Mesh Only - Fixed)");
  addOption(code_id[0], "Option 3 (1/2 mesh on hinge & hooks)", "Option 3 (1/2 mesh on hinge & hooks)");
  addOption(code_id[0], "Option 4 (2 panel - Full mesh & hooks)", "Option 4 (2 panel - Full mesh & hooks)");
}  
if(category_id[0].value == 'Bangle Stands') {
  addOption(code_id[0], "Custom - Please complete details below", "Custom - Please complete details below");
  addOption(code_id[0], "BGS-BLK-S (black sml) - $12.50", "BGS-BLK-S (black sml) - $12.50");
  addOption(code_id[0], "BGS-BLK-L (black lge) - $16.00", "BGS-BLK-L (black lge) - $16.00");
  addOption(code_id[0], "BGS-BRW-S (brown sml) - $12.50", "BGS-BRW-S (brown sml) - $12.50");
  addOption(code_id[0], "BGS-BRW-L (brown lge) - $16.00", "BGS-BRW-L (brown lge) - $16.00");
  addOption(code_id[0], "BGS-WHT-S (white sml) - $12.50", "BGS-WHT-S (white sml) - $12.50");
  addOption(code_id[0], "BGS-WHT-L (white lge) - $16.00", "BGS-WHT-L (white lge) - $16.00");
  
}
if(category_id[0].value == 'Necklace Stands') {
  addOption(code_id[0], "Custom - Please complete details below", "Custom - Please complete details below");
  addOption(code_id[0], "NS-S-BLK (small-black) - $24.00", "NS-S-BLK (small-black) - $24.00");
  addOption(code_id[0], "NS-S-WHT (small-white) - $24.00", "NS-S-WHT (small-white) - $24.00");
  addOption(code_id[0], "NS-S-BRW (small-brown) - $24.00", "NS-S-BRW (small-brown) - $24.00");
  addOption(code_id[0], "NS-S-PNK (small-pink) - $24.00", "NS-S-PNK (small-pink) - $24.00");
  addOption(code_id[0], "NS-L-BLK (large-black) - $30.00", "NS-L-BLK (large-black) - $30.00");
  addOption(code_id[0], "NS-L-WHT (large-white) - $30.00", "NS-L-WHT (large-white) - $30.00");
  addOption(code_id[0], "NS-L-BRW (large-brown) - $30.00", "NS-L-BRW (large-brown) - $30.00");
  addOption(code_id[0], "NS-L-PNK (large-pink) - $30.00", "NS-L-PNK (large-pink) - 30.00");
}
if(category_id[0].value == 'Earring Holders - Ornate Range') {
  addOption(code_id[0], "Custom - Please complete details below", "Custom - Please complete details below");
  addOption(code_id[0], "OR-S6-N (6x8 silver ornate no hooks) - $29.00", "OR-S6-N (6x8 silver ornate no hooks) - $29.00");
  addOption(code_id[0], "OR-S8-N (8x10 silver ornate no hooks) - $36.00", "OR-S8-N (8x10 silver ornate no hooks) - $36.00");
  addOption(code_id[0], "OR-S6-V3 (6x8 silver ornate vertical 3 hooks) - $30.50", "OR-S6-V3 (6x8 silver ornate vertical 3 hooks) - $30.50");
  addOption(code_id[0], "OR-S8-V3 (8x10 silver ornate vertical 3 hooks) - $37.80", "OR-S8-V3 (8x10 silver ornate vertical 3 hooks) - $37.80");
  addOption(code_id[0], "OR-S6-H4 (6x10 silver ornate horizontal 4 hooks) - $31.00", "OR-S6-H4 (6x10 silver ornate horizontal 4 hooks) - $31.00");
  addOption(code_id[0], "OR-S8-H4 (8x10 silver ornate horizontal 4 hooks) - $38.40", "OR-S8-H4 (8x10 silver ornate horizontal 4 hooks) - $38.40");
  addOption(code_id[0], "OR-B6-N (6x8 black ornate no hooks) - $29.00", "OR-B6-N (6x8 black ornate no hooks) - $29.00");
  addOption(code_id[0], "OR-B8-N (8x10 black ornate no hooks) - $36.00", "OR-B8-N (8x10 black ornate no hooks) - $36.00");
  addOption(code_id[0], "OR-B6-V3 (6x8 black ornate vertical 3 hooks) - $30.50", "OR-B6-V3 (6x8 black ornate vertical 3 hooks) - $30.50");
  addOption(code_id[0], "OR-B8-V3 (8x10 black ornate vertical 3 hooks) - $37.80", "OR-B8-V3 (8x10 black ornate vertical 3 hooks) - $37.80");
  addOption(code_id[0], "OR-B6-H4 (6x8 black ornate horizontal 4 hooks) - $31.00", "OR-B6-H4 (6x8 black ornate horizontal 4 hooks) - $31.00");
  addOption(code_id[0], "OR-B8-H4 (8x10 black ornate horizontal 4 hooks) - $38.40", "OR-B8-H4 (8x10 black ornate horizontal 4 hooks) - $38.40");
  addOption(code_id[0], "OR-I6-N (6x8 white ornate no hooks) - $29.00", "OR-I6-N (6x8 white ornate without hooks) - $29.00");
  addOption(code_id[0], "OR-I8-N (8x10 white ornate no hooks) - $36.00", "OR-I8-N (8x10 white ornate without hooks) - $36.00");
  addOption(code_id[0], "OR-I6-V3 (6x8 white ornate vertical 3 hooks) - $30.50", "OR-I6-V3 (6x8 white ornate vertical 3 hooks) - $30.50");
  addOption(code_id[0], "OR-I8-V3 (8x10 white ornate vertical 3 hooks) - $37.80", "OR-I8-V3 (8x10 white ornate vertical 3 hooks) - $37.80");
  addOption(code_id[0], "OR-I6-H4 (6x8 white ornate horizontal 4 hooks) - $31.00", "OR-I6-H4 (6x8 white ornate horizontal 4 hooks) - $31.00");
  addOption(code_id[0], "OR-I8-H4 (8x10 white ornate horizontal 4 hooks) - $38.40", "OR-I8-H4 (8x10 white ornate horizontal 4 hooks) - $38.40");
}
if(category_id[0].value == 'Earring Holders - Contemporary Range') {
  addOption(code_id[0], "Custom - Please complete details below", "Custom - Please complete details below");
  addOption(code_id[0], "SW-6x8-N (silver 6x8 without hooks) - $23.00", "SW-6x8-N (silver 6x8 without hooks) - $23.00");
  addOption(code_id[0], "SW-6x8-V3 silver 6x8 vertical 3 hooks) - $24.80", "SW-6x8-V3 (silver 6x8 vertical 3 hooks) - $24.80");
  addOption(code_id[0], "SW-6x8-H4 (silver 6x8 horizontal 4 hooks) - $25.40", "SW-6x8-H4 (silver 6x8 horizontal 4 hooks) - $25.40");
  addOption(code_id[0], "SW-8x10-N (silver 6x8 without hooks) - $26.00", "SW-810-N (silver 8x10 without hooks) - $26.00");
  addOption(code_id[0], "SW-8x10-V3 (silver 6x8 vertical 3 hooks) - $27.80", "SW-810-V3 (silver 8x10 vertical 3 hooks) - $27.80");
  addOption(code_id[0], "SW-8x10-H4 (silver 6x8 horizontal 4 hooks) - $28.40", "SW-810-H4 (silver 810 horizontal 4 hooks) - $28.40");
  addOption(code_id[0], "GL-4x10-N (gold 4x10 without hooks) - $19.00", "GL-4x10-N (gold 4x10 without hooks) - $19.00");
  addOption(code_id[0], "GL-4x10-V3 (gold 4x10 vertical 3 hooks) - $20.50", "GL-4x10-V3 (gold 4x10 vertical 3 hooks) - $20.50");
  addOption(code_id[0], "GL-4x10-H4 (gold 4x10 horizontal 4 hooks) - $21.00", "GL-4x10-H4 (gold 4x10 horizontal 4 hooks) - $21.00");
  addOption(code_id[0], "GL-6x8-N (gold 6x8 without hooks) - $19.00", "GL-6x8-N (gold 6x8 without hooks) - $19.00");
  addOption(code_id[0], "GL-6x8-V3 (gold 6x8 vertical 3 hooks) - $20.50", "GL-6x8-V3 (gold 6x8 vertical 3 hooks) - $20.50");
  addOption(code_id[0], "GL-6x8-H4 (gold 6x8 horizontal 4 hooks) - $21.00", "GL-6x8-H4 (gold 6x8 horizontal 4 hooks) - $21.00");
  addOption(code_id[0], "BKS-4x10-N (black 4x10 without hooks) - $19.00", "BKS-4x10-N (black 4x10 without hooks) - $19.00");
  addOption(code_id[0], "BKS-4x10-V3 (black 4x10 vertical 3 hooks) - $20.50", "BKS-4x10-V3 (black 4x10 vertical 3 hooks) - $20.50");
  addOption(code_id[0], "BKS-4x10-H4 (black 4x10 horizontal 4 hooks) - $21.00", "BKS-4x10-H4 (black 4x10 horizontal 4 hooks) - $21.00");
  addOption(code_id[0], "BKS-6x8-N (black 6x8 without hooks) - $19.00", "BKS-6x8-N (black 6x8 without hooks) - $19.00");
  addOption(code_id[0], "BKS-6x8-V3 (black 6x8 vertical 3 hooks) - $20.50", "BKS-6x8-V3 (black 6x8 vertical 3 hooks) - $20.50");
  addOption(code_id[0], "BKS-6x8-H4 (black 6x8 horizontal 4 hooks) - 21.00", "BKS-6x8-H4 (black 6x8 horizontal 4 hooks) - $21.00");
}
if(category_id[0].value == 'Earring Holders - Wood Collection') {
  addOption(code_id[0], "Custom - Please complete details below", "Custom - Please complete details below");
  addOption(code_id[0], "WBW-4x10-N (white brush 4x10 without hooks) - $19.00", "WBW-4x10-N (white brush 4x10 without hooks) - $19.00");
  addOption(code_id[0], "WBW-4x10-V3 (white brush 4x10 vertical 3 hooks) - $20.50", "WBW-4x10-V3 (white brush 4x10 vertical 3 hooks) - $20.50");
  addOption(code_id[0], "WBW-4x10-H4 (white brush 4x10 horizontal 4 hooks) - $21.00", "WBW-4x10-H4 (white brush 4x10 horizontal 4 hooks) - $21.00");
  addOption(code_id[0], "WBW-6x8-N (white brush wood 6x8 without hooks) - $19.00", "WBW-6x8-N (white brush 6x8 without hooks) - $19.00");
  addOption(code_id[0], "WBW-6x8-V3 (white brush wood 6x8 vertical 3 hooks) - $20.50", "WBW-6x8-V3 (white brush 6x8 vertical 3 hooks) - $20.50");
  addOption(code_id[0], "WBW-6x8-H4 (white brush wood 6x8 horizontal 4 hooks) - $21.00", "WBW-6x8-H4 (white brush 6x8 horizontal 4 hooks) - $21.00");
  addOption(code_id[0], "WBW-8x10-N (white brush 8x10 without hooks) - $24.00", "WBW-8x10-N (white brush 8x10 without hooks) - $24.00");
  addOption(code_id[0], "WBW-8x10-V3 (white brush 8x10 vertical 3 hooks) - $25.50", "WBW-8x10-V3 (white brush 8x10 vertical 3 hooks) - $25.50");
  addOption(code_id[0], "WBW-8x10-H4 (white brush 8x10 horizontal 4 hooks) - $26.00", "WBW-8x10-H4 (white brush 8x10 horizontal 4 hooks) - $26.00");
  addOption(code_id[0], "WBM-4x10-N (brown brush wood without hooks) - $19.00", "WBM-4x10-N (brown brush wood without hooks) - $19.00");
  addOption(code_id[0], "WBM-4x10-V3 (brown brush wood 4x10 vertical 3 hooks) - $20.50", "WBM-4x10-V3 (brown brush wood 4x10 vertical 3 hooks) - $20.50");
  addOption(code_id[0], "WBM-4x10-H4 (brown brush wood 4x10 horizontal 4 hooks) - $21.00", "WBM-4x10-H4 (brown brush wood 4x10 horizontal 4 hooks) - $21.00");
  addOption(code_id[0], "WBM-6x8-N (brown brush wood 6x8 without hooks) - $19.00", "WBM-6x8-N (brown brush wood 6x8 without hooks) - $19.00");
  addOption(code_id[0], "WBM-6x8-V3 (brown brush wood 6x8 vertical 3 hooks) - $20.50", "WBM-6x8-V3 (brown brush wood 6x8 vertical 3 hooks) - $20.50");
  addOption(code_id[0], "WBM-6x8-H4 (brown brush wood 6x8 horizontal 4 hooks) - $21.00", "WBM-6x8-H4 (brown brush wood 6x8 horizontal 4 hooks) - $21.00");
  addOption(code_id[0], "WBM-8x10-N (brown brush 8x10 without hooks) - $24.00", "WBM-8x10-N (brown brush 8x10 without hooks) - $24.00");
  addOption(code_id[0], "WBM-8x10-V3 (brown brush 8x10 vertical 3 hooks) - $25.50", "WBM-8x10-V3 (brown brush 8x10 vertical 3 hooks) - $25.50");
  addOption(code_id[0], "WBM-8x10-H4 (brown brush 8x10 horizontal 4 hooks) - $26.00", "WBM-8x10-H4 (brown brush 8x10 horizontal 4 hooks) - $26.00");
  }
if(category_id[0].value == 'Cabinet Hangers & Display Stands') {
    addOption(code_id[0], "10”/25cm (for 6x8 sizes) - $6.00", "10”/25cm (for 6x8 sizes) - $6.00");
  addOption(code_id[0], "8”/20cm (4 x 10 sizes OR 6x8 positioned horizontally only) - $5.00", "8”/20cm (4 x 10 sizes OR 6x8 positioned horizontally only) - $5.00");
  addOption(code_id[0], "Cabinet hanger (wall screw & hook set) - $3.00", "Cabinet hanger (wall screw & hook set) - $3.00");
}
if(category_id[0].value == 'Earring Holders - Extra Large & Other designs') {
  addOption(code_id[0], "Please insert the product code in the notes box below", "Please insert the product code in the notes box below");
}
}

function removeAllOptions(selectbox) {
  var i;
  for(i=selectbox.options.length-1;i>=0;i--) {
    //selectbox.options.remove(i);
    selectbox.remove(i);
  }
}


function addOption(selectbox, value, text) {
  var optn = document.createElement("option");
  optn.text = text;
  optn.value = value;

  selectbox.options.add(optn);
}

function SelectPaymentMethod() {
// on change of payment method this function will work

var voucher_detail_1_id=document.getElementById("VoucherDetail1");
var voucher_detail_2_id=document.getElementById("VoucherDetail2");
var voucher_detail_3_id=document.getElementById("VoucherDetail3");

if(document.ordering.paymentmethod.value == 'Gift Voucher') {
  voucher_detail_1_id.style.visibility="visible";
  voucher_detail_2_id.style.visibility="visible";
  voucher_detail_3_id.style.visibility="visible";
}
else {
  voucher_detail_1_id.style.visibility="hidden";
  voucher_detail_2_id.style.visibility="hidden";
  voucher_detail_3_id.style.visibility="hidden";
}
}

function fillGFLists() { 
// this function is used to fill the drop down lists on load for gift vouchers

//
//Delivery Methods
//
addOption(document.ordering.gf_deliverymethod, "Postage (charge will be confirmed)", "Postage (charge will be confirmed)");
addOption(document.ordering.gf_deliverymethod, "Email", "Email");
addOption(document.ordering.gf_deliverymethod, "Market collection", "Market collection");

//
//Deliver To
//
addOption(document.ordering.gf_deliverto, "Me (purchaser)", "Me (purchaser)");
addOption(document.ordering.gf_deliverto, "Gift recipient directly", "Gift recipient directly");

//
//Payment Methods
//
addOption(document.ordering.gf_paymentmethod, "Bank EFT (details will be provided)", "Bank EFT (details will be provided)");
addOption(document.ordering.gf_paymentmethod, "Cash on delivery", "Cash on delivery");
addOption(document.ordering.gf_paymentmethod, "Other (agreed)", "Other (agreed)");

}

function SelectDeliveryMethod() {
// on change of delivery method this function will work

var lblDesc_id=document.getElementById("lblDesc");
var txtValue1_id=document.getElementById("txtValue1");
var txtValue2_id=document.getElementById("txtValue2");

if(document.ordering.gf_deliverymethod.value == "Postage (charge will be confirmed)") {
  lblDesc_id.innerHTML = "<h3>Postage address:</h3>";
  txtValue1_id.value = "";
  txtValue2_id.value = "";

  txtValue1_id.style.visibility="visible";
  txtValue2_id.style.visibility="visible";
}
else
{
  if(document.ordering.gf_deliverymethod.value == "Email") {
    lblDesc_id.innerHTML = "<h3>Recipient email:</h3>";
    txtValue1_id.value = "";
    txtValue2_id.value = "";

    txtValue1_id.style.visibility="visible";
    txtValue2_id.style.visibility="hidden";
  }
  else
  {
    if(document.ordering.gf_deliverymethod.value == "Market collection") {
      lblDesc_id.innerHTML = "<h3>Market location/date:</h3>";
      txtValue1_id.value = "";
      txtValue2_id.value = "";

      txtValue1_id.style.visibility="visible";
      txtValue2_id.style.visibility="hidden";
    }
    else
    {
      lblDesc_id.innerHTML = "";
      txtValue1_id.value = "";
      txtValue2_id.value = "";

      txtValue1_id.style.visibility="hidden";
      txtValue2_id.style.visibility="hidden";
    }
  }
}
}

function fillHPLists() { 
// this function is used to fill the drop down lists on load for home parties

//
//Payment Methods
//
addOption(document.ordering.paymentmethod, "Bank EFT (details will be provided)", "Bank EFT (details will be provided)");
addOption(document.ordering.paymentmethod, "Cash", "Cash");
addOption(document.ordering.paymentmethod, "Other (agreed)", "Other (agreed)");

}

function SelectHostAddress() {
// on change of host address this function will work

var lblDesc1_id=document.getElementById("lblDesc1");
var lblDesc2_id=document.getElementById("lblDesc2");
var lblDesc3_id=document.getElementById("lblDesc3");
var txtValue1_id=document.getElementById("txtValue1");
var txtValue2_id=document.getElementById("txtValue2");

if(document.ordering.hostaddress.value == "No") {
  lblDesc1_id.innerHTML = "<h3>Contact name:</h3>";
  lblDesc2_id.innerHTML = "<h3>Contact number:</h3>";
  lblDesc3_id.innerHTML = "<h6>* Please provide details for this address:</h6>";
  txtValue1_id.value = "";
  txtValue2_id.value = "";

  txtValue1_id.style.visibility="visible";
  txtValue2_id.style.visibility="visible";
}
else
{
  lblDesc1_id.innerHTML = "&nbsp;";
  lblDesc2_id.innerHTML = "&nbsp;";
  lblDesc3_id.innerHTML = "&nbsp;";
  txtValue1_id.value = "";
  txtValue2_id.value = "";

  txtValue1_id.style.visibility="hidden";
  txtValue2_id.style.visibility="hidden";
}
}

/*************************************************************************
  This code is from Dynamic Web Coding 
  at http://www.dyn-web.com/
  Copyright 2001-3 by Sharon Paine 
  See Terms of Use at http://www.dyn-web.com/bus/terms.html
  Permission granted to use this code 
  as long as this entire notice is included.
*************************************************************************/
function initImgRotation() {
  // create rotating image objects here 
  // arguments: image name, rotation speed
  var rotator1 = new rotateImgObj('img1',2500);
  // add the images to rotate into that image object  
  rotator1.addImages("scroll1.jpg","scroll2.jpg","scroll3.jpg","scroll4.jpg");

  // starts rotation for all defined rotateImgObjs
  for (var i=0; i<rotateImgObjs.length; i++) 
	rotateImgObjs[i].timer = setInterval(rotateImgObjs[i].animString + ".rotate()", rotateImgObjs[i].speed);
}

// If all the images you wish to display are in the same location, you can specify the path here 
rotateImgObj.imagesPath = "images/";

rotateImgObjs = []; // holds all rotating image objects defined
// constructor 
function rotateImgObj(nm,s) {
  this.speed = s; this.ctr=0; this.timer=0;  
  this.imgObj = document.images[nm]; // get reference to the image object
  this.index = rotateImgObjs.length; rotateImgObjs[this.index] = this;
  this.animString = "rotateImgObjs[" + this.index + "]";
  
  this.addImages = addRotatingImages;
  this.rotate = rotateImg;
}
// preloads images
function addRotatingImages() {
  this.imgObj.imgs = [];
  for (var i=0; i<arguments.length; i++) {
	this.imgObj.imgs[i] = new Image();
	this.imgObj.imgs[i].src = rotateImgObj.imagesPath + arguments[i];
  }
}

// controls rotation
function rotateImg() {
  if (this.ctr < this.imgObj.imgs.length-1) this.ctr++;
  else this.ctr = 0;
  this.imgObj.src = this.imgObj.imgs[this.ctr].src;
}
