$(function(){
	var mouseMoveEvent;
	$().mousemove(function(e){
		mouseMoveEvent = e;
	}); 
   
	$('#ajaxLoadingIndicator').ajaxStart(function(){
		var offsetLeft = 20;
		//var offsetTop = $(this).height();
		var offsetTop = 0;
		var indicator = this;
		var handler = function(e){
			if (typeof(e) == "undefined") {
				return;
			}
			$(indicator).css({
				top: (offsetTop + e.pageY) + 'px',
				left: (offsetLeft + e.pageX) + 'px'
			});
		};
		$(document).bind('mousemove.ajaxLoadingIndicator', handler);
		handler(mouseMoveEvent);
		$(this).show();
	});
	
	$('#ajaxLoadingIndicator').ajaxStop(function(){
		$(this).hide();
		$(document).unbind('mousemove.ajaxLoadingIndicator');
	});
});

createSpecificComboSelectInternal = function (obj, extraParams) {
	if (obj.alreadyChangedToCheckboxesCombo) {
		return true;
	}
	
	var params = {maxDropHeight: 200};;
	if ($(obj).hasClass("firstChecksAll")) {
		params["firstItemChecksAll"] = true;
	}
	if ($(obj).hasClass("firstMeansAll")) {
		params["firstItemMeansAll"] = true;
	}
	//alert($(obj).parent().css("width"));
	if ($(obj).parent().css("width")) {
		params["width"] = parseInt($(obj).parent().css("width")) - 20;
	}
	if (extraParams != null) {
		//alert('extraParams not null. its: ' + extraParams);
		for (key in extraParams) {
			//alert(key + ': ' + extraParams[key]);
			params[key] = extraParams[key];
		}
		/*
		$(extraParams).each(function() {
			alert(this);
		});
		*/
	}
	
	$(obj).dropdownchecklist(params);
	obj.alreadyChangedToCheckboxesCombo = true;
	
	return true;
}

var createSpecificComboSelectExtraParams = Array();

createComboSelect = function () {
	$("select.multiSelectCombo").each(function() {
		var id = $(this).attr("id");
		createSpecificComboSelectInternal(this, createSpecificComboSelectExtraParams[id]);
		/*
		var params = {maxDropHeight: 200};;
		if ($(this).hasClass("firstChecksAll")) {
			params["firstItemChecksAll"] = true;
		}
		if ($(this).hasClass("firstMeansAll")) {
			params["firstItemMeansAll"] = true;
		}
		if ($(this).parent().css("width")) {
			params["width"] = parseInt($(this).parent().css("width")) - 20;
		}
		$(this).dropdownchecklist(params);
		this.alreadyChangedToCheckboxesCombo = true;
		*/
	});
}

var miscDisgustingDocumentIsReady = false;

createSpecificComboSelect = function (id, extraParams) {
	//alert('here: ' + extraParams);
	
	if (!miscDisgustingDocumentIsReady) {
		createSpecificComboSelectExtraParams[id] = extraParams;
		return false;
	}
	
	var obj = $("#" + id);
	if (!obj) {
		return false;
	}
	//alert('aaaaaaa');
	return createSpecificComboSelectInternal(obj, extraParams);
	/*
	if (obj.alreadyChangedToCheckboxesCombo) {
		return true;
	}
	
	var params = {maxDropHeight: 200};;
	if ($(obj).hasClass("firstChecksAll")) {
		params["firstItemChecksAll"] = true;
	}
	if ($(obj).hasClass("firstMeansAll")) {
		params["firstItemMeansAll"] = true;
	}
	//alert($(obj).parent().css("width"));
	if ($(obj).parent().css("width")) {
		params["width"] = parseInt($(obj).parent().css("width")) - 20;
	}
	$(obj).dropdownchecklist(params);
	obj.alreadyChangedToCheckboxesCombo = true;
	*/
}

$(document).ready(function(){
	createComboSelect();
	miscDisgustingDocumentIsReady = true;
});