var linkList = new Array();
linkList[1] = "https://discrete.propreports.com/login.php";
linkList[2] = "https://discretecad.propreports.com/login.php";
linkList[3] = "https://discretecad.propreports.com/login.php";
linkList[4] = "http://manager.discretetrading.com/extranet.php";

var select = $('select.DTlogin');

var linkBox = $('<div>',{
	width		: select.outerWidth(),
	className	: 'DTdropdown',
	html		: '<div class="loginLink"></div>'
});

var dropDown = $('<ul>',{className:'dropDown'});
var loginLink = linkBox.find('.loginLink');
	
select.find('option').each(function(i){
	var option = $(this);
	if(i==select.attr('selectedIndex')){loginLink.html(option.text());}
	if(option.data('skip')){return true;}
	var li = $('<li>',{html: '<div style="width:30px;height:20px;overflow:hidden;background-image:url(\''+option.data('icon')+'\');"></div><span>'+option.data('html-text')+'</span>'});
				
	li.click(function(){/*loginLink.html(option.text());*/ dropDown.trigger('hide'); select.val(option.val()); if(linkList[option.val()] != ""){window.open(linkList[option.val()])}; return false;});	
	dropDown.append(li);
});
	
linkBox.append(dropDown.hide());
select.hide().after(linkBox);
	
dropDown.bind('show',function(){
	if(dropDown.is(':animated')){return false;}
	loginLink.addClass('expanded');
	dropDown.slideDown();
}).bind('hide',function(){
	if(dropDown.is(':animated')){return false;}
	loginLink.removeClass('expanded');
	dropDown.slideUp();
}).bind('toggle',function(){
	if(loginLink.hasClass('expanded')){dropDown.trigger('hide');} else dropDown.trigger('show');
});
	
loginLink.click(function(){dropDown.trigger('toggle'); return false;});
	
$(document).click(function(){dropDown.trigger('hide');});
