function Dropdown(handler,dropdownBoxDiv,dropdownListDiv,selectBoxId) {

 this.arrow = new Image();
 this.arrow.src = 'images/currency_selector.gif';
 this.arrow_on = new Image();
 this.arrow_on.src = 'images/currency_selector.gif'
 this.arrow_down = new Image();
 this.arrow_down.src = 'images/currency_selector.gif';

 this.handler = handler;
 this.select = 0;
 this.dropdownBox = dropdownBoxDiv;
 this.dropdownList = dropdownListDiv;
 this.selectBox = selectBoxId;
 this.dropdownListTimer = null;

 this.list = function() {

 document.getElementById(this.dropdownBox).style.backgroundImage = "url('" + this.arrow.src + "')";

 var source = document.getElementById(this.selectBox);
 var dropdown = document.getElementById(this.dropdownList);
 dropdown.innerHTML = ""; // this doesn't quite comfort with standards - needs rewriting (using the W3C DOM)

 for (var i=0; i<source.options.length; i++) {
 var style = 'class="currency"';
 dropdown.innerHTML = dropdown.innerHTML + '<a class="currency1" href="javascript:' + this.handler + '.selectItem(' + i + ')">' + source.options[i].text + '</a>\n';
 }
 }

 this.selectItem = function(id) {
 var source = document.getElementById(this.selectBox);
 source.selectedIndex = id;
 this.setActive(source.options[id].text);
 this.click();
 }
 this.selectItem1 = function(id) {
 var source = document.getElementById(this.selectBox);
 source.selectedIndex = id;
 this.setActive(source.options[id].text);
 this.click1();
 }

 this.setActive = function(text) {
 document.getElementById(this.dropdownBox).innerHTML = text;
 }

 this.mouseon = function() {

 if (!this.select)
 document.getElementById(this.dropdownBox).style.backgroundImage = "url('" + this.arrow_on.src + "')";

 if (this.dropdownListTimer) {
 clearTimeout(this.dropdownListTimer);
 this.dropdownListTimer = null;
 }
 }

 this.click = function() {

 if (!this.select) {
   document.getElementById(this.dropdownBox).style.backgroundImage = "url('" + this.arrow_down.src + "')";
   document.getElementById(this.dropdownList).style.display = 'block';
   var listOffset = parseInt(document.getElementById(this.dropdownList).offsetHeight) + 36;
   var topPosition = getTopPosition(document.getElementById(this.dropdownBox));
   var windowHeight = getHeight();
   var diff = windowHeight - topPosition - listOffset;
   if (diff < 10) { document.getElementById(this.dropdownList).style.marginTop = '-'+listOffset+'px'; }
   else { document.getElementById(this.dropdownList).style.marginTop = ''; }
   this.select = 1;
 } else {
 document.getElementById(this.dropdownBox).style.backgroundImage = "url('" + this.arrow_on.src + "')";
 document.getElementById(this.dropdownList).style.display = 'none';
 this.select = 0;
 }
 }
 this.click1 = function() {
 document.getElementById(this.dropdownBox).style.backgroundImage = "url('" + this.arrow_on.src + "')";
 document.getElementById(this.dropdownList).style.display = 'none';
 }

 this.mouseout = function() {
 if (this.select) {
 this.dropdownListTimer = setTimeout(this.handler + ".click()",200);
 } else {
 document.getElementById(this.dropdownBox).style.backgroundImage = "url('" + this.arrow.src + "')";
 }
 }
}

function getHeight() {

	var h = 0;

	if(!window.innerWidth) {
		if(!(document.documentElement.clientWidth == 0)) {
			h = document.documentElement.clientHeight;
		}	else {
			h = document.body.clientHeight;
		}
	}	else {
		h = window.innerHeight;
	}

  return h;
}

function getTopPosition(obj) {
  var topValue= 0;
  while (obj) {
    topValue+= obj.offsetTop;
    obj= obj.offsetParent;
  }
  return topValue;
}
