$(function(){
	$('select').each(function(j) {
		var current = this;
		$(this).hide();
		var dropdown = $(this).attr('name');
		$(this).after('<div class="dd" id="'+dropdown+j+'"><div class="dd-head" id="'+dropdown+j+'"><a href="#"><img src="/images/close.gif" /><\/a><\/div><div class="dd-body"><ul id="'+$(this).attr('name')+'"><\/ul><\/div><\/div>');
		var first;
		$.each(current, function(n) {
			var option = "#"+dropdown+" #Option"+n+j;
			if (n == 0) {
				first = this;
				$(current).after('<div class="dd-outer"><div class="dd-button" id="'+dropdown+'Drop'+j+'">'+$(this).text()+'<\/div><\/div>');
				$('#'+dropdown+'Drop'+j).click(function() {
						$('#'+dropdown).parent().parent().css('display', (!$('#'+dropdown).parent().parent().is(':hidden')) ? 'none' : 'block');
					
				}).css('cursor','pointer');
				$("#"+dropdown+j+" img").click(function() {
						$('#'+dropdown).parent().parent().css('display', (!$('#'+dropdown).parent().parent().is(':hidden')) ? 'none' : 'block');
					
				});
			} else {
				if ($(this).val() == $(first).val()) {
					$('#'+dropdown).append("<li id='Option"+n+j+"' name='"+$(this).val()+"' class='selected'>"+$(this).text()+"<\/li>").css('cursor','pointer');
				} else {
					$('#'+dropdown).append("<li id='Option"+n+j+"' name='"+$(this).val()+"'>"+$(this).text()+"<\/li>").css('cursor','pointer');
				}
				$(option).click(function(event) {
						$('#'+dropdown+" li").each(function() {$(this).removeClass('selected')});
						$(current).val($(option).attr('name'));
						$(this).parent().parent().parent().css('display', 'none');
						$("#"+dropdown+'Drop'+j).text($(option).text());
						window.location = $(option).attr('name');
						$(this).addClass('selected');
					
				}).css('cursor','pointer');
			}
		})
	})


    $('#op_search').bind('click', function() {
        $('#searchform').submit();
    });
});

