/**
 * Tauscht die Klasse eines Objektes zwischen zwei Klassen
 * @author Alexander Wegener
 */
function switchClass(obj, class1, class2) {
    if (!isObject(obj)) {
        obj = $(obj);
    }

    if (obj.hasClassName(class1)) {
        obj.className = class2;
    } else if (obj.hasClassName(class2)) {
        obj.className = class1;
    }
    
    return obj.className;
}


/**
 * Gibt true zurück, falls der Parameter eine Funktion/ein
 * Objekt/ein Array/ein String/ein Integer ist
 * @author Alexander Wegener
 */
function isFunction(obj) {
    return (typeof(obj)=="function");
}
function isObject(obj) {
    return (typeof(obj)=="object");
}
function isArray(obj) {
    return (isObject(obj) && (obj.length) &&(!isString(obj)));
}
function isString(obj) {
    return (typeof(obj)=="string");
}
function isInt(str) {
    var i = parseInt(str);
    if (isNaN (i)) return false;
    i = i . toString();
    if (i != str) return false;
    return true;
}


/**
 * Überprüft, ob eine Funktion existiert
 * @author Alexander Wegener
 */
function functionExists(functionName) {
    return eval('(typeof ' + functionName + '==\'function\');');
}


/**
 * Sortiert ein multidimensionales Array nach der 'sort'-Spalte
 * @author Alexander Wegener
 */
function sortBySort(a, b) {
    return ((a.sort < b.sort) ? -1 : ((a.sort > b.sort) ? 1 : 0));
}


/**
 * Sortiert ein multidimensionales Array nach der 'title'-Spalte
 * @author Alexander Wegener
 */
function sortByTitle(a, b) {
    return ((a.title.toLowerCase() < b.title.toLowerCase()) ? -1 : ((a.title.toLowerCase() > b.title.toLowerCase()) ? 1 : 0));
}

function removeIndexFromAssocArray(remove_index, my_array) {
    var new_array = new Array();
    
    for (var index in my_array) if (!my_array[index].prototype) { 
        if (index != remove_index) {
            new_array[index] = my_array[index];
        }
    }
    return new_array;
}


/**
 *
 * @author Alexander Wegener
 */
function getIndexByPropertyValue(myArray, myProperty, myValue) {
    t1 = myArray.pluck(myProperty)
    return t1.indexOf(myValue);
}