var iDropdownTimeout;
var objCurrentDropdown;

function initialise_all_partytopia_dropdowns() {
	var allLinks = document.getElementsByTagName('a');
	for (i = 0; i < allLinks.length; i++) {
		if (allLinks[i].className == 'dropdown_long' || allLinks[i].className == 'dropdown_medium' || allLinks[i].className == 'dropdown_short') {
			initialise_single_partytopia_dropdown(allLinks[i]);
		}
	}
}

function initialise_single_partytopia_dropdown(objLink) {
	objLink.onmouseover = function() {
		partytopia_dropddown_over(objLink);
	}
	objLink.onmouseout = function() {
		clearTimeout(iDropdownTimeout);
		objCurrentDropdown = objLink;
		iDropdownTimeout = setTimeout('partytopia_current_dropddown_out()', 1000);
	}
}

function partytopia_short_dropdown_select(args) {
    // do nothing!
}

function partytopia_dropdown_select(objListItem, action) {

	// get the link and the clicked list items value...
	var objLink = objListItem.parentNode.parentNode;
	var sItemValue = objListItem.innerHTML;

	// find the div inside the link and set its value to the clicked list items value...
	var arrDivsInLink = objLink.getElementsByTagName('div');
	arrDivsInLink[0].innerHTML = sItemValue;

	// find the input field inside the link and set its value to the clicked list items value...
	var arrInputsInLink = objLink.getElementsByTagName('input');
	arrInputsInLink[0].value = sItemValue;

	// hide the dropdown...
	partytopia_dropddown_out(objLink);
	
	

	//if action is true then make action
	if (action) {
		//alert('blah');
	    var id = arrInputsInLink[0].id;
	    id = id.replace("LongListValue", "bAction");
	    id = id.replace("MediumListValue", "bRun");
	    var elem = document.getElementById(id);
	    //alert(elem.id);
	    doFire(elem.id);
		
	}

}

function partytopia_dropddown_over(objLink) {

	// hide the current dropdown...
	partytopia_current_dropddown_out()

	// show the dropdown...
	var arrListsInLink = objLink.getElementsByTagName('ul');
	arrListsInLink[0].style.display = 'block';

	objLink.style.zIndex = 200;

	// set the look of the dropdown link to the hover position...
	switch ( objLink.className ) { 
		case 'dropdown_long':
			objLink.style.backgroundPosition = '-900px 1px';
			break;
		case 'dropdown_medium':
			objLink.style.backgroundPosition = '-400px 0';
			break;
		case 'dropdown_short':
			objLink.style.backgroundPosition = '-100px 0';
			break;
	}
}
function partytopia_current_dropddown_out() {
	if ( objCurrentDropdown ) {
		partytopia_dropddown_out(objCurrentDropdown);
	}
	objCurrentDropdown = null;
}
function partytopia_dropddown_out(objLink) {
	// hide the dropdown...
	var arrListsInLink = objLink.getElementsByTagName('ul');
	arrListsInLink[0].style.display = 'none';
	
	objLink.style.zIndex = 100;
	
	// set the look of the dropdown link to the default position...
	switch ( objLink.className ) { 
		case 'dropdown_long':
			objLink.style.backgroundPosition = '-600px 1px';
			break;
		case 'dropdown_medium':
			objLink.style.backgroundPosition = '-300px 0';
			break;
		case 'dropdown_short':
			objLink.style.backgroundPosition = '0 0';
			break;
	}
}

function doFire(objID) {
    if (document.all) {	//IE
        //document.getElementById(objID).fireEvent("onClick");
		document.getElementById(objID).click();
        return;
    }

    //Firefox
    var clickEvent = window.document.createEvent("MouseEvent");
    clickEvent.initMouseEvent("click", true, true, this, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
    document.getElementById(objID).dispatchEvent(clickEvent);

}
