// drowtales community rotating images dropdown box 
// written by mladyjade (mladyjade@yahoo.com) for Kern of http://www.drowtales.com
// do not reuse without permission

// happy 21st birthday Kern!

/********************************************************************************************/
// field 0 - URL for the link
// field 1 - title of the link
// field 2 - URL to the image for the link, if it exists.

var cmtyLinkList = [
   [""," - Community's manga : -"],
   ["http://www.chibikaki.com"            ,"Souls Through Darkness"    ,"http://www.drowtales.com/community/soulsthroughdarkness.gif"],
   ["http://www.elfcomic.com"             ,"There Be Elves"            ,"http://www.drowtales.com/community/therebeelves.jpg"],
   ["http://shamdu.drowtales.com"         ,"Darkness Rising"           ,"http://www.drowtales.com/community/darknessrising.jpg"],
   ["http://www.terinu.net"               ,"Terinu"                    ,"http://www.drowtales.com/community/terinu.jpg"],
   ["http://thesins.drowtales.com"        ,"The Sins"                  ],
   ["http://www.desperateangels.com"        ,"Desperate Angels"          ,"http://www.drowtales.com/community/desperatesangel.jpg"],
   ["http://www.worldofdragonsbreath.com" ,"Word of Dragons Breath"    ,"http://www.drowtales.com/community/worldofdragonsbreath.jpg"],
   ["http://phoenixdawn.drowtales.com'"   ,"Phoenix Dawn"              ],
   ["http://www.worldofdragonsbreath.com/firebrand/","Firebrand"       ,"http://www.drowtales.com/community/firebrand.jpg"],
   ["http://kay.drowtales.com"            ,"Kay the Cookie Dragon"     ],
   ["http://www.trilokan.com"             ,"Trilokan"                  ,"http://www.drowtales.com/community/trilokan.jpg"],
   ["http://shiningknight.drowtales.com"  ,"Shining Knight"            ],
   ["http://demoncurse.drowtales.com"     ,"Demon's Curse"             ,"http://www.drowtales.com/community/demoncurse.jpg"],
   ["http://quantum-rip.com"               ,"Quantum Rip"               ,"http://www.drowtales.com/community/quantumrip.jpg"],
   ["http://vastar.drowtales.com"         ,"Vastar"                    ,"http://www.drowtales.com/community/vastar.jpg"],
    ["http://bhv.drowtales.com"            ,"By Her Voice"              ,"http://www.drowtales.com/community/byhervoice.jpg"],
   ["http://saganovel.drowtales.com"           ,"Saga Novel"   ,"http://www.drowtales.com/community/saganovel.gif"],
["http://snserenity.drowtales.com/"           ,"Sakkaku no Serenity"   ,"http://www.drowtales.com/community/serenity.gif"],
["http://mariana.drowtales.com/"           ,"Drow cop"   ,"http://www.drowtales.com/community/mariana.jpg"],
["http://crosswind.drowtales.com/"           ,"Crosswind"   ,"http://www.drowtales.com/community/crosswind.gif"],
["http://redallover.drowtales.com/"           ,"Redallover"   ,"http://www.drowtales.com/community/redallover.jpg"],
["http://tartuga.drowtales.com/"           ,"Tartuga"   ,"http://www.drowtales.com/community/tartuga.jpg"],
["http://quixote.drowtales.com/"           ,"Quixote"   ,"http://www.drowtales.com/community/quixote.png"]
];

/********************************************************************************************/

var OP = (navigator.userAgent.indexOf('Opera')>-1);
var NS = (document.getElementById&&!document.all);
var IE = (document.all);

function initCmtyImages() {
   for (i=0; i < cmtyLinkList.length ; i++ ) {
      if ( cmtyLinkList[i][2] ) {
         cmtyLinkList[i][3] = new Image();
         cmtyLinkList[i][3].src = cmtyLinkList[i][2];
      }
   }
}

function getCmtyItems() {
   var itxt = "<option selected value =''>" + cmtyLinkList[0][1] + "</option>\n";
   for ( i = 1 ; i < cmtyLinkList.length ; i++ ) {
      if ( cmtyLinkList[i][0] ) {
         itxt += "<option value = '" + cmtyLinkList[i][0] + "'>";
      } else {
         itxt += "<option value=''>";
      }
      itxt += cmtyLinkList[i][1] + "</option>\n";
   }
   return itxt;
}

function getCmtyDoChange() {
   var cdctxt;
   if (NS) {
	   cdctxt = "if (document.getElementById('cmtydropdown').selectedIndex != 0) document.location = document.getElementById('cmtydropdown').options[document.getElementById('cmtydropdown').selectedIndex].value; else alert('Select a manga!');";
   } else { 
	   cdctxt = "if (document.all('cmtydropdown').selectedIndex != 0) document.location = document.all('cmtydropdown').options[document.all('cmtydropdown').selectedIndex].value; else alert('Select a manga!');";
   }
   return cdctxt;
}

function getCmtyStyle() {
   var cmts = "<style>\n";
   
   cmts += "#cmtybutton {width:170; height:25;}\n";
   cmts += "#cmtydropdown {width:170;}\n";
   cmts += "</style>\n";
   
   return cmts;
}


function writeCmtyImgBox() {
   
   initCmtyImages(); // initialize the images

   var cmtyTxt = getCmtyStyle();
   var doChange = getCmtyDoChange();
   
   // table around image and box
   cmtyTxt += "<table ";
   cmtyTxt += "align='center' border='0'";
   cmtyTxt += "cellspacing='0' cellpadding='0'>\n";
   cmtyTxt += "<tr><td>\n";

   // image on top of selection box
   cmtyTxt += "<a href='" + cmtyLinkList[1][0] + "' name='cmtylink'";
   cmtyTxt += "id='cmtylink'>\n";
   cmtyTxt += "<img border='0' src='" + cmtyLinkList[1][2] + "'";
   cmtyTxt += "name='cmtybutton' id='cmtybutton'><br>\n";
   cmtyTxt += "</a>";

   // table between image and box
   cmtyTxt += "</td></tr><tr><td>\n";

   // selection box
   cmtyTxt += "<select ";
   cmtyTxt += "size='1' name='cmtydropdown' id='cmtydropdown' ";
   cmtyTxt += "class='drowdropdown' ";
   cmtyTxt += "onchange=\"" + doChange + "\">\n";

   // selection box items
   cmtyTxt += getCmtyItems();

   // end box
   cmtyTxt += "</select>\n";

   // end table
   cmtyTxt += "</td></tr></table>\n";
   
   // write the dropdown
   document.write(cmtyTxt);
}

function cmtyRotateImgs() {
   var nameButton = "cmtybutton";
   var nameLink = "cmtylink";
   
   var docCall;
   if (NS){
      docCall= document.getElementById(nameLink);
   } else {
      docCall= document.all(nameLink);
   }
   
   cmtyCnt++;
   if ( cmtyCnt >= cmtyLinkList.length ) {
      cmtyCnt = 1;
   }

   // skip links that have no img
   while ( !(cmtyLinkList[cmtyCnt][3]) ) {
      cmtyCnt++;
      // make sure we don't go off the end of the array
      if ( cmtyCnt >= cmtyLinkList.length ) {
         cmtyCnt = 1;
      }
   }
   
   document.images[nameButton].src = cmtyLinkList[cmtyCnt][3].src;
   docCall.href = cmtyLinkList[cmtyCnt][0];
}

/********************************************************************************************/

var cmtyCnt = 0;
var cmtyRotate = setInterval('cmtyRotateImgs();',4000);

/********************************************************************************************/

writeCmtyImgBox();