function InitCustomPicker() {
   

    //Reroute any assetimagepicker calls to slightly customised page which uses assetportalbrowserextended
    if (CONST_EditImageDialogDialogName) {
        CONST_EditImageDialogDialogName = "AssetImagePickerExtended.aspx";
    }
}
InitCustomPicker();

//Redirect to assetportalbrowserextended + pass in some configuration through the query string
ImageAsset.prototype.LaunchModalAssetPicker = function(Config) {

    var selectorObject = document.getElementById(Config.ClientID);

    var newName = "AssetPortalBrowserExtended.aspx";

    var customAttributes = "";

    if (selectorObject["__GlobalPickerID"] != null) {

        var name = selectorObject["__GlobalPickerID"];

        var extendedConfigObject;
        eval("extendedConfigObject=" + name + ";")

        var customAttributes = '&' + encodeAttributesIntoQueryString(extendedConfigObject);

    }

    var selectorObj = document.getElementById(Config.ClientID);

    var fullDialogUrl = Config.GetDialogUrl(newName);

    fullDialogUrl += "?APDView=Thumbs&" + Config.GenerateQueryStringSegment() + "&Filter=1&" + this.GenerateQueryStringSegment() + "&Custom_IsFirstLoad=true"+ customAttributes + "&Custom_OriginHostName=" + window.location.hostname;
    return Config.LaunchUrlWithAsset(fullDialogUrl, this, CONST_ImageAssetPickerDialogFeatures)

};

LinkAsset.prototype.LaunchModalAssetPicker = function(Config) {
    var selectorObject = document.getElementById(Config.ClientID);
    var newName = "AssetPortalBrowserExtended.aspx";

    if (selectorObject["__GlobalPickerID"] != null) {

        var name = selectorObject["__GlobalPickerID"];

        var extendedConfigObject;
        eval("extendedConfigObject=" + name + ";");

        var customAttributes = '&' + encodeAttributesIntoQueryString(extendedConfigObject);

        CONST_LinkAssetPickerDialogName = newName;
    }

    var fullDialogUrl = "";

    var selectorObj = document.getElementById(Config.ClientID);


    fullDialogUrl = Config.GetDialogUrl(CONST_LinkAssetPickerDialogName);

    fullDialogUrl += "?" + Config.GenerateQueryStringSegment() + "&Filter=1&" + this.GenerateQueryStringSegment() + customAttributes + "&Custom_OriginHostName=" + window.location.hostname;

    return Config.LaunchUrlWithAsset(fullDialogUrl, this, CONST_LinkAssetPickerDialogFeatures)
};


function encodeAttributesIntoQueryString(configObj) {
    return Custom_GenerateSerializedObjectQString(configObj, 'Custom_');
}

function Custom_GenerateSerializedObjectQString(objectToSerialize, prefix) {
    var isFirstProp = true;
    var propType;
    var qStringSegmentToReturn = "";

    for (prop in objectToSerialize) {
        propType = typeof (objectToSerialize[prop]);
        if ("string" == propType || "boolean" == propType || "number" == propType) {
            if (prop.indexOf(prefix) == 0) {
                qStringSegmentToReturn = AP_InsertQParamToQString(prop, objectToSerialize[prop], qStringSegmentToReturn);
                if ("true" == AP_GetCurrentQParamValue("DebugQString")) { alert("Adding: " + prop + "(" + typeof (objectToSerialize[prop]) + ")=[" + objectToSerialize[prop] + "]\n" + qStringSegmentToReturn); }
            }
        }
    }
    return qStringSegmentToReturn;
}
    